Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#backup-cheatsheet

Linux Backup (Rsync & Rclone) Cheatsheet

Regular backups are crucial for data integrity. rsync is the standard tool for local and SSH-based backups, while rclone is the standard for backing up to cloud storage providers (Google Drive, S3, Dropbox, etc.).

Rsync (Local & SSH Backups)

rsync syncs files and directories from one location to another, transferring only the changed parts of files.

Common Flags:

  • -a : Archive mode (preserves permissions, times, symlinks, recursive)
  • -v : Verbose (show progress)
  • -z : Compress file data during the transfer
  • --delete : Delete files in the destination that no longer exist in the source
# Local backup (Copy folder A to folder B)
rsync -av /path/to/source/ /path/to/destination/
 
# Push backup to a remote server via SSH
rsync -avz /local/folder/ user@remote_ip:/remote/folder/
 
# Pull backup from a remote server via SSH
rsync -avz user@remote_ip:/remote/folder/ /local/folder/
 
# Exact Mirroring (Deletes files on destination if deleted on source)
rsync -avz --delete /local/folder/ user@remote_ip:/remote/folder/
 
# Dry Run (Test what will be synced without actually doing it)
rsync -av --dry-run /source /destination

Rclone (Cloud Backups)

rclone requires a configuration step to link your cloud accounts.

rclone config                 # Interactive menu to add a new cloud provider

Once configured (e.g., named gdrive):

# List files in the root of the cloud drive
rclone ls gdrive:
 
# Copy files (only copies new/changed files, doesn't delete)
rclone copy /local/folder gdrive:/backup/folder
 
# Sync files (makes destination exactly match source, WILL DELETE files)
rclone sync /local/folder gdrive:/backup/folder
 
# Mount cloud storage as a local disk (requires fuse)
rclone mount gdrive:/ /mnt/cloud --daemon

Automating Backups with Cron

To automate backups, add them to your crontab (crontab -e).

# Run the rsync backup every day at 2:00 AM
0 2 * * * rsync -avz --delete /var/www/ user@backup_server:/backups/www/