13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 4 ■ TAKING BACKUPS AND MANAGING DATA■ Note This will use ssh to backupserver as root, which may or may not be permitted on your system. Ifbackupserver isn’t on your local network, you’ll need to specify its address in full: backupserver.example.com.rsyncd must be running on backupserver. To set this up, install the relevant package for your distro(in Debian/Ubuntu it’s rsyncd), then edit /etc/default/rsync to set RSYNC_ENABLE to true, and finally run/etc/init.d/rsync start.You’ll be challenged for your ssh password (see recipe 6-3 for how to avoid this), and then rsync willlog a message to the screen that it is building the file list. This means that it is working out what files tocopy. In this case, it’ll copy all of them, because this is a first backup. Once the list is built, the copyingwill start, and using the -v switch means there’ll be a message logged to the screen for each file.Once rsync has finished, your backed-up files will be in /shared/backuphome on backupserver.example.com.■ Note rsync’s treatment of directories differs depending on whether there is a trailing slash at the end of thesource directory. The following:rsync /test/one /backupwill transfer all the files in /test/one to /backup/one. In other words, it copies the whole directory (and itscontents) by name. By contrast, the following, with the trailing slash on the source directory:rsync /test/one/ /backupwill copy all the files in /test/one to /backup. In other words, it copies only the contents, not the directory itself.Most of the time, you’ll want to use the first version because it is tidier in the sense that it keeps all the files withinthe copied directory rather than scattered into your parent backup directory.Once your first run has finished, try changing a single file and running the same command again.You’ll see that only a single file is copied this time.To avoid the ssh password challenge, you could also use mount to mount the shared backupdirectory over NFS. This script, run from homeserver, will mount the directory, run the rsync, andunmount the directory; it doesn’t use the -v (verbose) option to rsync so that output is reduced. Save itas /etc/cron.d/home-backup-script.mount -t nfs backupserver:/shared/backuphome /mntrsync -avuz /shared/home /mntumount /mnt106Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!