#!/usr/bin/perl
### Design By Andrew Choi
### Backup Directory
@backuppool = ("ntpool/u0","ntpool/local");
$targetpool = "backup";
$record = "/$targetpool/zfs-backup-record.dat";
### Main Program
# Gen Date Code
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time;
$year = $year + 1900;
$mon = substr "0".$mon,-2;
$mday = substr "0".$mday,-2;
$hour = substr "0".$hour,-2;
$min = substr "0".$min,-2;
$sec = substr "0".$sec,-2;
$datecode = $year.$mon.$mday.$hour.$min.$sec;
# Check the last record of record file
open (FILE,"<$record");
@temp = <FILE>;
close (FILE);
$lastrecord = pop(@temp);
chop ($lastrecord);
# Save the update datecode
open (FILE,">>$record");
print FILE"$datecode\n";
close (FILE);
# Create snapshot
foreach $pool(@backuppool) {
$command = "zfs snapshot $pool\@$datecode\n";
print $command;
$a = `$command`;
}
# Backup method
if ($lastrecord eq "") {
# Full Backup
foreach $pool(@backuppool) {
$command = "zfs send $pool\@$datecode \| zfs recv -F $targetpool/$pool\n";
print $command;
$a = `$command`;
}
} else {
# Incremental Backup
foreach $pool(@backuppool) {
$command = "zfs send -i $pool\@$lastrecord $pool\@$datecode \| zfs recv -F $targetpool/$pool\n";
print $command;
$a = `$command`;
}
}
# clean-snapshot.pl
#!/usr/bin/perl
### Design By Andrew Choi
### Clean snapshot
@backuppool = ("ntpool/u0","ntpool/local");
$targetpool = "backup";
$record = "/$targetpool/zfs-backup-record.dat";
### Main Program
# Check the last record of record file
open (FILE,"<$record");
@temp = <FILE>;
close (FILE);
if ($temp[0] eq "") {print "No any snapshot for clean\n"; exit;}
# Clean snapshot method
foreach $datecode(@temp) {
chop ($datecode);
foreach $pool(@backuppool) {
$command = "zfs destroy $pool\@$datecode\n";
$a = `$command`;
print $command;
$command = "zfs destroy $targetpool/$pool\@$datecode\n";
$a = `$command`;
print $command;
}
}
# Remove the record file
$command = "rm $record\n";
print $command;
$a = `$command`;
[ 發表回應 ] ( 19預覽 ) | 常註連結 | ( 2.8 / 1715 )