Thursday, April 28, 2011

Rsync, Level: Expert

Learning all kinds of new things, like how to escape spaces in filenames. When I tried the command
$ sudo rsync -avr --progress /etc/ /media/FreeAgent Backup/etc/
I got only error messages. What works is quoting,
sudo rsync -avr --progress /etc/ "/media/FreeAgent Backup/etc/"
or escaping:
sudo rsync -avr --progress /etc/ /media/FreeAgent\ Backup/etc/
. I back up /etc as it's small, and may be useful. The main thing to backup, of course, is /home:
sudo rsync -avr --progress /home/valorie/ "/media/FreeAgent Backup/home/"
where /home is the source, and /media/FreeAgent Backup/ is the destination. Thanks to sbeattie and maco in #ubuntu-women for showing me this.

Also, empty trash BEFORE running a backup of /home!
sudo rm -r /home/valorie/.local/share/Trash/*
. In #ubuntu-women, JanC suggested using "the GUI or a special commandline tool to empty the trash, as it keeps references around etc. The trash-cli package contains a command
." When I asked what she meant by references, JanC explained, "references as to what file has to be restored to where (if you ever want to do so). And of course there are separate trash directories on every disk you have etc. AFAIK trash-cli implements the XDG spec about this, just like GNOME & KDE do."

In #kubuntu-offtopic, James147 suggested that rather than just emptying the trash, I use --exclude=, ie rsync ... --exclude=*/Trash/* --exclude=*.tmp --exclude=*.bak ... etc. He suggested "useful patterns might be: *.tmp *.bak *.backup *~ *.swp */lost+found/*. I really wish I had thought to do this, and I definitely will in future. Watching that stuff scroll past as I waited was not fun!

I asked, "so each of the excludes needs to be separate, like: --exclude=*/Trash/* --exclude=*.tmp --exclude=*.bak"

[15:27] <james147> yes
[15:27] <james147> each pattern you want to exclude needs a separate --exclude=
[15:27] <james147> ^^ can get long but thats what scripts are for :D
[15:28] <valorie> that maybe my next step
[15:28] <valorie> for now, a good string I can copy/paste will be good

[15:29] <james147> valorie: a script isn't hard to do...

[15:29] <valorie> the up-arrow in bash makes things pretty easy
[15:30] <james147> valorie: can be as simple as
1. #!/bin/bash
   2. rsync ... --exclude=*.tmp --exclude=/Trash/* ... # add and edit this line till it suits your needs
[15:30] ^^ then you just need to run "chmod +x scriptname"
[15:31] then run it with ./scriptname or bash scriptname or sh scriptname
[15:31] (use sudo if it needs root)
[15:31] valorie: bash scripts can just be a bunch of commands you want to run

I'm not quite ready to wrap all this into a script, but will definitely think about do so before my next backup. discussing scripting the backup process too. For now, on to Natty Narwhal!