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 DATALine 19 does all the heavy lifting. It creates a tar archive called $tarfile from the files in@archivelist. Line 20 sends the e-mail. Having this as a subroutine makes testing easier. You can quicklycomment out the e-mail sending step while you’re checking that the archive is being correctlygenerated. If you do run it like this, you should see the gmailtar.tgz file in the directory you ran thescript from. Check its contents with this:mkdir testmv gmailtar.tgz test/cd test/tar zxf gmailtar.tgzls test/*The sendmail() subroutine in lines 27–34 is straightforward. It creates a new MIME message,attaches the gzipped backup file, and sends it as a message.As it stands, the script will leave the tar file it creates on your machine. To delete this, add an extraline after line 20:unlink $tarfile;If you don’t do this, the tar file will simply be overwritten the next time the script runs.■ Note You probably don’t want to have the delete line in during testing because you may want to look at thearchive file after the script has run.To make this include more than one directory, replace line 15 with this:my @backupdir = ("/dir1/", "/dir2/");Replace line 18 with these three lines:foreach my $dir ( @backupdir ) {find ( \&wanted, $dir );}Use crontab to run this daily. Run crontab -e, and then edit your crontab to look something likethis:13 04 * * * /path/to/script4-9. Using anacron for Laptop Backupscron is great for servers and desktops that are always on, but if you want to schedule a backup (or indeedany other job) on a laptop or another machine that may not always be on, you’re probably better offusing anacron instead.112Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!