Skip to content

Instantly share code, notes, and snippets.

@EvanLyu732
Created September 13, 2024 07:09
Show Gist options
  • Save EvanLyu732/7dfab5b62f07886100a96f1069b21707 to your computer and use it in GitHub Desktop.
Save EvanLyu732/7dfab5b62f07886100a96f1069b21707 to your computer and use it in GitHub Desktop.
rsync backup entire root folder
sudo rsync -avxHAX --progress --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*/.cache/*","/var/cache/*","/var/tmp/*"} / /path/to/backup/destination/

Let's break down this rsync command:

  1. sudo: Run the command with root privileges, necessary for accessing all system files.

  2. rsync: The command itself.

  3. Options:

    • -a: Archive mode, which preserves almost everything
    • -v: Verbose, for more detailed output
    • -x: Don't cross filesystem boundaries
    • -H: Preserve hard links
    • -A: Preserve ACLs (Access Control Lists)
    • -X: Preserve extended attributes
    • --progress: Show progress during transfer
  4. --exclude={}: This excludes certain directories that are either unnecessary for backup or could cause issues if included:

    • /dev/*, /proc/*, /sys/*: Virtual filesystems
    • /tmp/*, /run/*: Temporary files
    • /mnt/*, /media/*: Mount points
    • /lost+found: Used by fsck
    • /home/*/.cache/*, /var/cache/*, /var/tmp/*: Cache directories
  5. /: The source directory (root of the filesystem)

  6. /path/to/backup/destination/: Replace this with the actual path where you want to store the backup

To use this command:

  1. Replace /path/to/backup/destination/ with your actual backup location.
  2. Run the command in a terminal.

Some important notes:

  • Ensure your backup destination has enough space.
  • This backup will take a significant amount of time, depending on your system size and backup destination speed.
  • Consider running this in a screen or tmux session if you're doing it over SSH, to prevent interruption if your connection drops.
  • You might want to add or remove exclusions based on your specific needs.

Would you like me to explain any part of this command further or discuss strategies for scheduling regular backups?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment