in reply to Just another backup script

I'm just curious about a few things.

  1. Why backticks to get the day? Why not just use localtime and sprintf it yourself (there are many date-time modules that can make this simple, too)?
  2. Why system(STR) instead of system(LIST)? Get rid of the shell for all that. Though this won't help with the md5sum since you're actually using the shell to make it really simple to create your sums.md5 file, which is fine, since you're really using the shell. The rest should not have any shell special characters in them, so using the LIST form would be more explicit for catching errors should they appear (at this point, it'd be most likely while adding features).
  3. Why duplicate $day? I'd probably suggest that you put everything in ~/backup/$day, and skip the $day in the filenames.
  4. Why taronly anything? It's not like gzip costs you anything. As I had a conversation with a co-worker just the other day, the overhead of using gzip in CPU time is usually (always in our case at $work) overwhelmed by the disk I/O time of writing the difference that gzip saves. And, in your case, it would mean fewer things to think about or evaluate. Just tar.gz everything, no special cases for the non-compressed stuff.
  5. Is it that advantageous to archive each directory separately? Unless the combined total of all these directories started getting to be too large for your file system to handle, I'd think it'd just be far more convenient to put everything into a single tarball. You can still extract individual directories, or even files, should you need to.
  6. Normally, the purpose of a backup is to have your files in case the physical disk they're on fail. You're putting the backups presumably on the same partition, so you're merely staving off accidental deletes, not catastrophic failures. You should be putting the files on a separate disk, which means it probably should be a "my $backupdir = '/nfs/othermachine/backups/';" at the top somewhere that you use as the basis for the backups. (And it should use a subdirectory that is named based on your current hostname, followed by the user it's backing up, just to ensure uniqueness, before putting in the date.) Of course, if you don't have said other machine, you can still point it to your home directory, but at least you'll have written the flexibility in for when you do get that far.
Mind you, that all might just be me. :-)

++ for automation.

Replies are listed 'Best First'.
Re^2: Just another backup script
by sundance_kid (Sexton) on Sep 01, 2009 at 08:34 UTC
    I agree with all the comments from Tanktalus. I will add some info that could also be useful.

    - Why calling shell commands? Unless speed is really an issue, Archive::Tar is quite handy and it is a core module. The same could be applied to md5 calculations, which could be made using Digest::MD5 (also a core module).

    - There's a nice module IPC::System::Simple that handles very well all the system and exec calls, taking good care of edge cases, portability and return values, dying on error.

    - For quick date formating, I always do the following:

    use POSIX qw/strftime/; $date = strftime( '%Y%m%d', localtime time );

    Good luck!

      Thanks for comments, I've found them very informative and I hope I'll improve my coding style using your advices in the future.

      @Tanktalus -- After I make backup-$day directory I usually burn it on CD/DVD using external application.