Backing Up Files and Directories with rsync

Backing Up with rsync

rsync is the standard Linux tool for efficient, incremental file backups. It only transfers changed files, making backups fast even for large directories.

Basic Syntax

rsync [options] source destination

Common Flags

  • -a — archive mode (preserves permissions, timestamps, symlinks, owner, group)
  • -v — verbose (show files being transferred)
  • -z — compress data during transfer
  • --progress — show transfer progress
  • --delete — delete files at destination that no longer exist at source
  • --exclude — skip certain files or directories

Local Backup

rsync -avz /var/www/ /backup/www/

Remote Backup (to Another Server)

rsync -avz /var/www/ user@backup-server:/backup/www/

Mirror a Directory (Delete Removed Files)

rsync -avz --delete /var/www/ /backup/www/

Exclude Directories

rsync -avz --exclude='cache/' --exclude='*.log' /var/www/ /backup/www/

Dry Run (Preview Without Making Changes)

rsync -avz --dry-run /var/www/ /backup/www/

Schedule Nightly Backups with Cron

crontab -e
# Add:
0 2 * * * rsync -az --delete /var/www/ /backup/www/ >> /var/log/rsync_backup.log 2>&1
  • 0 Kunder som kunne bruge dette svar
Hjalp dette svar dig?

Relaterede artikler

Managing Users and Groups

Managing Users and Groups on Linux Proper user management is essential for server security. Avoid...

Managing Services with systemctl

Managing Services with systemctl systemctl is the standard tool for managing services on modern...

Monitoring Server Resources

Monitoring Server Resources Keeping an eye on your server's resource usage helps you identify...

Scheduling Tasks with Cron

Scheduling Tasks with Cron Cron allows you to schedule commands to run automatically at set...

Installing and Configuring Nginx

Installing and Configuring Nginx Nginx is a high-performance web server and reverse proxy widely...