Backups

By Hal Canary, 2004-03-13 21:22:49 (link)
#computers-code

I've decided to back up my mp3 collection for the first time ever. It's a whopping 14 Gb. which I split up among 21 CDs.

I'll be burning all night.

At least I automated the task somewhat. I wrote a script that softlinks the files into directories each less than 700000kb.

Be sure to use “mkisofs -f” (follow symbolic links).

#!/usr/bin/perl
#
#DTPD#
#
# Arguments: file containing list of
#   files to be backed up.
#
# To Do: Jolietify (64 char filename).
#        Preserve directory structure.

$backupdir = "\$HOME/MP3_BACKUP";
system("mkdir -p $backupdir");
$num=1;
$dirnum = &padnum($num);
system("mkdir $backupdir/$dirnum");
while ($file = <>) {
    chomp ($file);
    @ar = split (/\//, $file);
    $short = pop(@ar);
    $dir = "$backupdir/$dirnum";
    $new = "$dir/$short";
    &link($file,$new);
    $size = `du -Ls "$dir"`;
    chomp ($size);
    if ($size > 700000) {
        system("rm \"$new\"");
        $num++;
        $dirnum = &padnum($num);
        $dir = "$backupdir/$dirnum";
        system("mkdir -p $dir");
        $new = "$dir/$short";
        &link($file,$new);
    }
}
sub link {
    my $o = shift;
    my $l = shift;
    system("ln -s \"$o\" \"$l\"");
}
sub padnum {
    my $num=shift;
    return "00".$num if $num<10;
    return "0".$num if $num<100;
    return "$num";
}

(back)