A valid backup must be tested. Do not limit yourself to checking that the file/directory exists.
1. What to back up
/etc(configurations)- Application data (e.g.
/var/www,/srv) - Database dumps (before rsync)
- Custom scripts and cron
2. Suggested structure
/backup/
current/
logs/
snapshots/ # optional
/usr/local/sbin/backup-rsync.sh
3. Basic Bash script
#!/usr/bin/env bash
set -euo pipefail
DEST="/backup/current"
LOG="/backup/logs/backup-$(date +%F).log"
SRC=("/etc" "/var/www")
EXCLUDES=("/var/www/cache" "/var/www/tmp")
mkdir -p "$DEST" "$(dirname "$LOG")"
RSYNC_OPTS=(-aHAX --delete --numeric-ids)
for e in "${EXCLUDES[@]}"; do
RSYNC_OPTS+=(--exclude "$e")
done
{
echo "== Backup start $(date) =="
for s in "${SRC[@]}"; do
rsync "${RSYNC_OPTS[@]}" "$s" "$DEST/"
done
echo "== Backup end $(date) =="
} | tee -a "$LOG"
Make it executable:
chmod +x /usr/local/sbin/backup-rsync.sh
4. Manual test before cron
/usr/local/sbin/backup-rsync.sh
ls -lh /backup/logs
du -sh /backup/current
5. Schedule with cron (Slackware: rc.crond)
Make sure the cron service is active:
chmod +x /etc/rc.d/rc.crond
/etc/rc.d/rc.crond start
Add the job (as root):
crontab -e
# Backup every night at 02:30
30 2 * * * /usr/local/sbin/backup-rsync.sh
6. Retention and rotation (simple)
To avoid filling disk, delete old logs and consider separate snapshots.
find /backup/logs -type f -name 'backup-*.log' -mtime +30 -delete
If you want real versioning, use hardlink snapshots (
cp -al) or filesystems with native snapshots (e.g. btrfs/zfs if available in your setup).7. Restore test (critical)
mkdir -p /tmp/restore-test
rsync -a /backup/current/etc/ /tmp/restore-test/etc/
ls -l /tmp/restore-test/etc | head
For critical data, try a restore on a test machine.
8. Best practices
- Back up to a separate disk or remote host
- Use
screen/tmuxfor long manual backups over SSH - Keep logs readable and check them periodically
- Do not back up cache, sockets, pseudo-filesystems (
/proc,/sys,/dev)
Quick checklist
[ ] rsync script created and tested
[ ] rc.crond enabled and started
[ ] Cron job configured
[ ] Excludes defined
[ ] Logs and retention configured
[ ] Restore test executed