rsync example using ssh and excluding files
When excluding files, if the file is in the foot directory, you should prefix it with a forward slash, otherwise it will mean any file.
The example below is backing up a PmWiki installation. It's excluding the .htaccess and config.php that is in the root of that directory. Without the forward slash, it will exclude any file with the name .htaccess and config.php. I'm also excluding the sectionedit.php file by pointing to it with a relative path. This path is relative to the root directory, although I'm not sure.
#!/bin/bash source="/var/www/pmwiki/htdocs/" host="user1@www.host1.com" destination="/path/to/backup/pmwiki/htdocs/" rsync -rlt --exclude="/.htaccess" --exclude="/config.php" --exclude="cookbook/sectionedit/sectionedit.php" -e ssh $source $host:$destination
Of course to use ssh with a cron job, we're going to need to setup public key authentication on the destination machine. You can find instructions at UnixNotes#sWiki.UnixNotes_27. You can also search this wiki for ssh or public key authentication. I know there's a really good page somewhere in the wiki.
Rsync with SSH
I use the command,
$ rsync -av -e ssh $source $user@$host:$destination
$source is the path to whatever directories or files you want to backup.
$user@$host is of the form joe@www.example.com
$destination is the path to the directory you want to backup your files to.
A complete example would be,
$ rsync -av -e ssh /home/joefoo/scripts /home/joefoo/tokeep joefoo@www.example.com:/path/to/backups/joefoo/
The way I have it setup, the directory scripts and tokeep will be put inside the directory joefoo. By not putting a slash after the source directories, it puts the actual directory in the joefoo directory. If I had done something like /home/joefoo/scripts/ then the contents of scripts would be put in joefoo and not the directory itself.
Here's a nice BASH script to do this
TODO MAKE THIS LIVE. IT'S COMMENTED OUT FOR NOW.
Gentoo stuff
Change rsyncd.conf location
In gentoo, the rsyncd.conf file is located at /etc/rsyncd.conf. To move it inside /etc/rsync, edit /etc/conf.d/rsyncd and add the following line,
RSYNC_OPTS="--config /etc/rsync/rsyncd.conf --address <your_servers_ip>"
Starting rsyncd when your computers starts
You may want to start the rsync server when your computer boots up. Issue the following command to do so,
# rc-update add rsyncd default
Setting the motd
When you edit /etc/rsync/rsyncd.motd, a user will be presented with the contents when they access your rsync server.
Basic command to backup files locally
I'm using
rsync -vrlptD /dir/to/backup /dir/to/backup/to
| -v | verbose |
| -r | recursive into directories |
| -l | copy symlinks as symlinks |
| -p | preserve permissions |
| -t | preserve times |
| -D | preserve devices and special files |
[Click to add or edit comments])
Please prepend comments below including a date