
Backing Up User Data to a Server with rsync
|
239
There are many more rsync options that may come in useful in specialized situa-
tions. You can find these on the manpage.
After the options, the arguments are the source and destination. Both
source and
destination can be paths to local files on the computer where rsync is running, rsync
server designations (generally used for download file servers), or
user@host:path des-
ignations for ssh. Because rsync takes so many options and long arguments that
won’t regularly change, next we’ll write a bash script to run it.
Making a User Backup Script
This section presents a simple bash script that makes a backup from a user’s desktop
to the backup server. The name of the backup server is assigned to the variable
dest
in this script. The variable user is assigned the username of the account that runs the
script by running the whoami command and capturing the output as a string. The cd
command changes the current directory to the user’s home directory. The logical-OR
test condition that follows the cd command aborts the script if there is a failure. The
one dot (
.) all by itself specifies the current directory as the source argument. For the
destination argument, we specify the username and hostname to log in as via ssh,
followed by a dot to specify the current home directory on the destination host.
Here’s the script:
#!/bin/bash
export RSYNC_RSH=/usr/bin/ssh