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 DATAMake it executable with chmod u+x /etc/cron.d/home-backup-script.Finally, you need to automate this. Type crontab -e, and add this line to your crontab file:5 0 * * * /etc/cron.d/backupscriptThe numbers at the start of the crontab entry mean that this will run at five (5) minutes pastmidnight (0) every day (check the crontab man 5 page for more details).■ Note One issue with this setup is that you have only one day’s version, so if something happens to your diskovernight, the “bad” version may be written as the backup.To avoid this, you could set up a cronjob on your backup machine that runs just before the scheduled rsync andcopies your existing backup directory elsewhere. For example, this line in your crontab would do the job:5 23 * * * rsync -auz --delete /home/user/backup /home/user/backup2This runs at 11:05 p.m. daily. It would keep only one extra day’s worth of data, but that might be enough for you.You could extend this to keep more backups, but this has a high disk space penalty (although disk these days ischeap), and there quickly comes a point where you are better off relying on your tape backups.If you do have a disaster, you can now just rewrite your LDAP NFS maps (see recipe 2-13) to usebackupserver:/shared/homebackup rather than homeserver:/shared/home, and everyone can access theirfiles again (albeit with possibly up to 24 hours lost) while you fix the problem. This script will rewrite theLDAP maps for you:01 #!/usr/bin/perl -w02 use strict;03 use Net::LDAPS;0405 my $ldapserver = 'ldapserver.example.com';06 my $base = 'ou=people,dc=example,dc=com';06 my $oldhome = 'homeserver:/homedisk/';07 my $newhome = 'newserver:/newhome/';0809 my $ldap = Net::LDAPS->new( $ldapserver,10 verify => 'optional',11 cafile => '/etc/ldap/cacert.pem' ) or die $@;12 my $mesg = $ldap->bind;1314 $mesg = $ldap->search( base => $base,15 filter => "automountInformation=*$oldhome*",107Download at WoweBook.Com

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

Saved successfully!

Ooh no, something went wrong!