Skip to Main Content
Linux System Administration
book

Linux System Administration

by Tom Adelstein, Bill Lubanovic
March 2007
Intermediate to advanced content levelIntermediate to advanced
304 pages
11h 12m
English
O'Reilly Media, Inc.
Content preview from Linux System Administration
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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux System Administration

Mastering Linux System Administration

Christine Bresnahan, Richard Blum
Mastering Linux Administration

Mastering Linux Administration

Alexandru Calcatinge, Julian Balog

Publisher Resources

ISBN: 9780596009526Supplemental ContentCatalog PageErrata