Showing posts with label rsync. Show all posts
Showing posts with label rsync. Show all posts

Full system backup with rsync in linux

This command depends on brace expansion available in both the bash and zsh shells. When using a different shell--exclude patterns should be repeated manually.
# rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /* /path/to/backup/folder
Using the -aAX set of options, the files are transferred in archive mode, ensuring that symbolic links, devices, permissions and ownerships, modification times, ACLs and extended attributes are preserved.
The --exclude option will cause files that match the given patterns to be excluded. The contents of /dev/proc/sys/tmp and /run were excluded because they are populated at boot (while the folders themselves are not created), /lost+found is filesystem-specific. Quoting the exclude patterns will avoid expansion by shell, which is necessary e.g. when backing up over SSH.
Note:
  • If you plan on backing up your system somewhere other than /mnt or /media, do not forget to add it to the list of exclude patterns to avoid an infinite loop.
  • If there are any bind mounts in the system, they should be excluded as well, so that the bind mounted contents is copied only once.
  • If you use a swap file, make sure to exclude it as well.
  • Consider also if you want to backup the /home/ folder. If it contains your data, it might be considerably larger than the system. Otherwise consider excluding unimportant subdirectories such as /home/*/.thumbnails/*/home/*/.cache/mozilla/*/home/*/.cache/chromium/*/home/*/.local/share/Trash/*, depending on software installed on the system. If GVFS is installed, /home/*/.gvfs must be excluded to prevent rsync errors.