--delete (it removes files from the destination that no longer exist on the source).
user@serverrsync installed on both machines (server and backup host)sudo apt update
sudo apt install -y rsync
sudo dnf install -y rsync
ssh-keygen -t ed25519 -a 64
ssh-copy-id user@server
~/.ssh/config entries to simplify the rsync command.rsync -avz --progress --dry-run \
-e "ssh -p 22" \
user@server:/etc/ /backups/server/etc/
-a archive mode (preserves perms, times, symlinks)-v verbose-z compression--dry-run don’t change anything--dry-run and (optionally) add --delete:
rsync -avz --delete --progress \
-e "ssh -p 22" \
user@server:/home/ /backups/server/home/
--delete deletes on the destination. Use only if the destination should be an exact mirror of the source.
cat > excludes.txt <<'EOF'
*.tmp
*.cache
.cache/
node_modules/
EOF
rsync -avz --delete --progress \
--exclude-from="excludes.txt" \
-e "ssh -p 22" \
user@server:/var/www/ /backups/server/var_www/
/usr/local/bin/backup_server.sh on the backup host):
#!/usr/bin/env bash
set -euo pipefail
rsync -avz --delete \
--exclude-from="/backups/excludes.txt" \
-e "ssh -p 22" \
user@server:/home/ /backups/server/home/
crontab -e
# Every day at 2:15 AM
15 2 * * * /usr/local/bin/backup_server.sh >> /var/log/backup_server.log 2>&1
du -sh /backups/server/home/
ls -la /backups/server/etc/ | head
rsync -avz --progress \
/backups/server/etc/ user@server:/etc/