24

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?

  • 1
    besides .Trash, there's frequently also .Trash-1000 (under current Ubuntu-MATE 14 at least), so better settle for .Trash-*? – Frank Nocke Feb 26 '17 at 12:43
41

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 section at the start with folders, that are directories, probably not worth a backup.

  • 2
    You can combine the two commands, since rsync can read from stdin: wget https://... -O - | rsync -a --progress --exclude-from=- ... – muru Nov 4 '14 at 18:08
  • 9
    good point, but I think it is recommendable first to look at the ignorelist before starting the rsync – rubo77 Nov 4 '14 at 18:17
  • surprisingly node_modules isn't on the list – jchook Nov 3 '18 at 21:11
  • don't you want to keep node_modules in some of your config directories? Imagine, you want to move your home directory to a new computer, you would need to keep those then. – rubo77 Nov 4 '18 at 15:28
4

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.
  • There is such a list, I edited my question – rubo77 Nov 4 '14 at 17:40
  • @rubo77 I stand by my statement that there's no list of all folders you could exclude. That's a recommendation, and I doubt even Lekenstyn would say it's a complete list. – muru Nov 4 '14 at 17:43
  • The list doesn''t have to be complete I just would like to create my backup faster so skip obvious useless folders – rubo77 Nov 4 '14 at 17:44
  • @rubo77 I think you'll have to shift the comments to different lines. – muru Nov 4 '14 at 17:52
  • thx, I updated the gist file so the comments are on single lines – rubo77 Nov 4 '14 at 18:04
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

  • Can you be more specific "quotest missing"? – arth May 17 '15 at 16:34
  • Oh, sorry - I was terse, and messed it up by a typo: "quotest" instead of "quotes" missing. – Volker Siegel May 17 '15 at 16:58
  • The shell could expand the * (maybe not in that place?). The paths should be quoted - the user name can not contain a space, but /media/ could be /Old Media/ or so... – Volker Siegel May 17 '15 at 17:02
  • I apologize I am not getting it. The '.*' is to not include any '.' pattern which are hidden directories at home directory '/home/$USER/' to backup destination: external hdd or pen drive '/media/$USER/folder'. By doing this, only the actual directories and files are being backup. If you're pointing something else, please elaborate. – arth May 17 '15 at 18:23
  • 4
    It is not really sensefull to exclude all directories starting with a dot, for example .thunderbird directory is one of the most important directories – rubo77 May 17 '15 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.