| PetesProjects: Backing Up With Perl | ||
|
<<< Backing Up with Bash
![]() Files that are described here: A full backup is easy to do: just grab the files (or directories of files) mentioned in the list, add them to a tar file, compress that and add the date of the backup. Done. But doing an incremental backup is a little more involved. You need to know which files were modified or created since the last full backup. Which means you need to know when the last full backup was created, and when each file was modified or created. Well, the full backup has a timestamp. So do all files and directories. So, it's possible you could just check the date of the last full backup, right? But what if it's not around? What if it's stored away somewhere, such as on a CD, and then deleted from the hard drive? You want to go dig up that CD just to do an incremental backup? Not me. What I do is "touch" the Perl script that does incremental backups, whenever I do full backups. That way the date of the last full backup is always conveniently available, even if the last full backup isn't. So, to find those files that have been modified or created since the last full backup, just go through the original backup list and check the dates of all the files. As each directory is searched, each file is examined. If it's newer than the last full backup, its name goes into an incremental backup list, called incbackuplist. The Perl script that does incremental backups is called bu2. Just like backmeup, bu2 can be called with just the name of the file: bu2. But it can also take three command line parameters: the name of the full backup file list, the name of the incremental backup file list, and the name of the incremental backup itself. First we get to home directory, as defined by your account's environmental variables. If your home is /home/Sue, then change /home/Peter to /home/Sue (or whatever your system requires to indicate your home directory). Otherwise assume the current working directory is where you want to be to create the backup. Problem: You just modified bu2, and now its modification date isn't the same as the last full backup, which you made on the last day of November, at 3 minutes before 10 in the morning. What do you do? Type 'touch -t 0311300957 bin/bu2' at a system prompt. This will set the date of bin/bu2 to November 30, 2003, 09:57. Then define some variables, pick up any command line arguments, and set absolute paths for files to be opened. The script will open the backup list used for full backups, read in names of files and directories, locate those that are newer than the script itself, insert those filenames into the incremental backup file list and write it. At the very end of the Perl script, the bash script is called using the system command, and the arguments are included to indicate the name of the tar file, the name of the incremental backup file list, and "inc" which will alert the bash script that it will be doing an incremental backup. It really doesn't matter what that third argument is, as long as something is there that isn't "1" (which is the default value, meaning do a full backup). |
|
|