41

You can easyly backup your home folder on an external harddrive with

rsync -a --exclude=.cache --progress /home/$USER/ /media/linuxbackup/home/$USER/

I excluded the .cache folder cause I think I will never need it when I have to re-install from this backup.

I found this list of all folders that I could exclude in a normal backup here:
What files and directories can be excluded from a backup of the home directory?

I created a list of this answer that contains some coments in this form:

#These directories may be excluded:

.gvfs # contains mounted file systems? .local/share/gvfs-metadata .Private # contains the actual encrypted home directory .dbus # session-specific .cache .Trash # do I need to say more? .local/share/Trash .cddb # cached info about audio CDs .aptitude # cached packages lists

#Flash-specific:

.adobe # Cache for flash, maybe others? .macromedia # except for Flash persistence, there is no reason to keep this

#Files:

.xsession-errors # contains errors from the current graphical session .recently-used # recently used files .recently-used.xbel .thumbnails

Here is the full list at gist

How can I add this list to my rsync command?

rubo77
  • 34,024
  • 52
  • 172
  • 299

4 Answers4

62

The exclude list may only contain filenames, foldernames and lines starting with #. A comment behind the foldername is not allowed. I created a Git repository with all known files and folders that are superfluous:

Download this ignorelist to /var/tmp/ignorelist

wget https://raw.githubusercontent.com/rubo77/rsync-homedir-excludes/master/rsync-homedir-excludes.txt -O /var/tmp/ignorelist

Then start the rsync with

rsync -aP --exclude-from=/var/tmp/ignorelist /home/$USER/ /media/$USER/linuxbackup/home/

Note:
In the ignorelist there is a commented section at the start with folders, that are probably not worth a backup either. Uncomment those, you don't need.

rubo77
  • 34,024
  • 52
  • 172
  • 299
5

From man rsync:

 --exclude-from=FILE     read exclude patterns from FILE
          This option is related to the --exclude option, but it specifies
          a FILE that contains exclude patterns  (one  per  line).   Blank
          lines  in  the  file  and  lines  starting  with  ’;’ or ’#’ are
          ignored.  If FILE is -, the list  will  be  read  from  standard
          input.
muru
  • 207,228
0

Use rsync-homedir-excludes on Github ->

  1. download the excluded list (rsync-homedir-local.txt)->

    wget https://raw.githubusercontent.com/rubo77/rsync-homedir-excludes/master/rsync-homedir-excludes.txt -O rsync-homedir-local.txt

  2. Edit the file to meet your needs ->

    nano rsync-homedir-local.txt

  3. Create a backup directory (some examples)

    BACKUPDIR=/media/workspace/home/$USER

    BACKUPDIR=/media/$USER/linuxbackup/home/$USER

    BACKUPDIR=/media/$USER/USBSTICK/backup/home/$USER

  4. Use the "-n" parameter so rsync will simulate its operation. You should use this before you start:

    rsync -naP --exclude-from=rsync-homedir-local.txt /home/$USER/ $BACKUPDIR/

  5. Check for permission denied errors in your homedir ->

    rsync -naP --exclude-from=rsync-homedir-local.txt /home/$USER/ $BACKUPDIR/ | grep denied

  6. if it is all fine, actually perform your backup ->

    rsync -aP --exclude-from=rsync-homedir-local.txt /home/$USER/ $BACKUPDIR/

Aindriú
  • 141
  • 1
  • 7
0

Could try this if directories and files within are all you want backing-up. Excludes all hidden directories.

rsync -aP --exclude=.* /home/$USER/ /media/$USER/folder

arth
  • 9