Slackware HowTo

Backup on Slackware with rsync and cron

Simple backup script, cron scheduling, logs, and restore checks.

A valid backup must be tested. Do not limit yourself to checking that the file/directory exists.

1. What to back up

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

Quick checklist

[ ] rsync script created and tested
[ ] rc.crond enabled and started
[ ] Cron job configured
[ ] Excludes defined
[ ] Logs and retention configured
[ ] Restore test executed

Back to the Linux HowTo section