Custom Backup Script: Weekly Backups with Monthly Retention
I’m sharing a custom backup script I use for my HestiaCP server. It creates weekly backups (4 per month) and automatically keeps only the most recent backup from previous months, helping save disk space while maintaining a good backup history.
Features:
- Creates organized backups in date-structured directories (e.g.,
/backup/12 DEC 2025/) - Maintains symlinks in
/backup/for HestiaCP panel compatibility - Symlinks are essential - they allow HestiaCP to update backup counters correctly and enable users to download, restore, and delete backups from the panel, even though backups are organized in monthly folders
- Automatically cleans orphaned backups
- Optional: Keep only 1 backup per user from previous months (configurable)
- HTML email notifications with full backup summary
- Detailed logging for each backup session
- Database integrity checks before backup
- Robust cleanup of temporary files and incomplete backups
Installation:
-
Create the script file:
nano /usr/local/hestia/bin/v-backup-users-custom -
Paste the script content (I’ll provide it below)
-
Set proper permissions:
chmod 755 /usr/local/hestia/bin/v-backup-users-custom -
In HestiaCP Admin Panel:
- Go to Settings → Backups
- Ensure “Local backup” is enabled
- Go to Cron Jobs
- Find the existing backup cron job:
00 01 * * 0 sudo /usr/local/hestia/bin/v-backup-users - Change it to:
00 01 * * 0 sudo /usr/local/hestia/bin/v-backup-users-custom - Adjust the time as needed (current example: Sunday at 1:00 AM)
Configuration Options:
At the top of the script, you can customize:
# Auto-detect admin user with ROLE='admin' (leave empty)
ADMIN_USER_OVERRIDE=""
# Use CONTACT email from admin user (leave empty)
# Or set manually: ADMIN_EMAIL_OVERRIDE="[email protected]"
ADMIN_EMAIL_OVERRIDE=""
# Keep only 1 backup per user from previous months (TRUE/FALSE)
# When TRUE: Keeps only the most recent backup from previous months
# When FALSE: Keeps all backups (default HestiaCP behavior)
KEEP_ONLY_ONE_OLD_BACKUP="FALSE"
How it works:
- Runs weekly (or as configured in cron)
- Creates backups in organized folders:
/backup/DD MMM YYYY/username/ - Maintains symlinks in
/backup/for panel compatibility- These symlinks are crucial - they allow HestiaCP to:
- Update backup counters (
U_BACKUPS) correctly - Display backups in the user panel
- Enable download, restore, and delete functions
- All functions work normally despite backups being organized in monthly folders
- Update backup counters (
- These symlinks are crucial - they allow HestiaCP to:
- If
KEEP_ONLY_ONE_OLD_BACKUP="TRUE", automatically removes old backups from previous months, keeping only the latest one per user - Sends HTML email summary with backup status
- Logs everything for troubleshooting
User Panel Compatibility:
Even though backups are stored in organized monthly folders, all HestiaCP panel functions work perfectly:
- Users can see their backups in the panel
- Download backups directly
- Restore backups with one click
- Delete backups from the panel
- Backup counters are updated correctly
This is possible because the script maintains symlinks in the /backup/ directory that point to the actual backup files in the organized folders.
Remote Backup Support:
You can customize this script to work with remote backups (FTP, SFTP, B2, Rclone) by modifying the backup functions. The script is based on HestiaCP’s original v-backup-user logic but with enhanced organization and cleanup features.
**Script:
**
https://github.com/webxtekagency/hestiacp-useful-tools/tree/main/scripts/backup-users-custom
Notes:
- This script replaces the standard
v-backup-usersfor scheduled backups - You can still run manual backups using the original command
- All backups remain compatible with HestiaCP’s restore functions
- The script includes error handling and cleanup for interrupted backups
- Symlinks ensure full panel functionality while maintaining organized storage
Feedback and improvements welcome