[BACK]Return to backup.pl CVS log [TXT][DIR] Up to [local] / wpscripts / wpbackup

File: [local] / wpscripts / wpbackup / backup.pl (download)

Revision 1.1, Fri Jun 3 09:28:47 2011 UTC (11 years, 2 months ago) by yason
Branch point for: MAIN

Initial revision

#!/usr/bin/perl

use dirops;

our @image;
our $label;
our $ret;

dirops::walkthrough();

while(@image = dirops::getnextblk())
{
	# for each returned block

	$label = (split(/\//, $image[0]))[4];
	$label = $label . '-' . (split(/\//, $image[-1]))[4];
	
	print "Creating directory $dirops::IMAGE/$label.. ";
	if(!mkdir("$dirops::IMAGE/$label"))
	{
	    print "failed [$!]\n";
	    next;
	    # NOTREACHED
	}
	print "done\n";
	
	# open file in just crated directory
	# XXX need to be more verbose here
	open(INDEX, ">>$dirops::IMAGE/$label/INDEX") or next;
	print INDEX scalar(localtime()) . "\n";
	
	# move files there
	for(my $i = 0; $i < scalar(@image); $i++)
	{
	    print "moving $image[$i] to $dirops::IMAGE/$label .. ";
	    $ret = system("/bin/mv $image[$i] $dirops::IMAGE/$label");
	    
	    if($ret != 0)
	    {
		# mv returns error
		print "failed\n";
		
		# XXX should be more good here
		# maybe not to die ?
		die("cannot move $image[$i] to $dirops::IMAGE/$label! $!");
	    
	    }
	    # okay
	    print "done\n";
	    
	    # update INDEX
	    print INDEX "$image[$i]\n";
	}
	
	close(INDEX);
	
	# make ISO 9660 filesystem image
	$ret = system("/usr/local/bin/mkisofs -o $dirops::IMAGE/$label.iso $dirops::IMAGE/$label");
	if($ret != 0)
	{
	    # error 
	    print "error in making of isofs!\n";
	}
	else
	{
	    # image ready
	    # XXX cleanup
	    print "system(\"/bin/rm -r $dirops::IMAGE/$label\")\n";
	}
}