Thread: PING
View Single Post
Old 10-07-07, 08:46 AM   #6
evilghost
Registered User
 
Join Date: Jul 2005
Posts: 3,606
Default Re: PING

Here's the perl code I threw together to keep X days of backups, and here's the backup script I use on the server. I cron'd it in /etc/cron.daily

Cleanup
Code:
#!/usr/bin/perl

$popauthspool = "/backup/archives"; #Directory containing the files
$watcherlog = "/backup/backup_cleanup.log";

$date = localtime();

open(LOG,">>$watcherlog") || die("Can't open $watcherlog");
use File::stat;

@ips = `ls $popauthspool`;
foreach $ip (@ips) {
        chop($ip);
        $file = $popauthspool ."/". $ip;
        $s = stat($file) || die "Can't stat($file) $!\n";

        #1 day = 86400
        $modtime = $s->mtime + (86400 * 7);
        $now = time;
        if($modtime < $now){
                push(@expired,$ip);
        }
}

foreach $expired (@expired){
  $date = localtime();
  print LOG "$date - Removing $expired\n";
  unlink($popauthspool ."/". $expired);
}
close(LOG);
Backup Code
Code:
#!/bin/sh
/backup/backupcleanup.sh

echo "`date` Starting Backup" > /backup/backup.log

nice --adjustment=20 tar zcvpf /backup/archives/fullbackup-`/bin/date +%m-%d-%Y`.tgz --exclude=/FileServer --exclude=/backup/archives --exclude=/media --exclude=/home --exclude=/www_chroot --exclude=/sys --exclude=/rsync /
echo "`date` Full System Done" >> /backup/backup.log

nice --adjustment=20 tar zcvpf /backup/archives/home-`/bin/date +%m-%d-%Y`.tgz /home
echo "`date` Home Done" >> /backup/backup.log

nice --adjustment=20 tar zcvpf /backup/archives/www-`/bin/date +%m-%d-%Y`.tgz /www_chroot
echo "`date` WWW Done" >> /backup/backup.log

nice --adjustment=20 tar zcvpf /backup/archives/luser-`/bin/date +%m-%d-%Y`.tgz /home/luser
echo "`date` luser Done" >> /backup/backup.log

nice --adjustment=20 tar zcvpf /backup/archives/FileServer-`/bin/date +%m-%d-%Y`.tgz --exclude=/FileServer/Music /FileServer
echo "`date` FileServer Done" >> /backup/backup.log

nice --adjustment=20 tar zcvpf /backup/archives/rsync-`/bin/date +%m-%d-%Y`.tgz /rsync
echo "`date` rsync Done" >> /backup/backup.log

ssh root@192.168.1.254 -p 57600 -C 'dd if=/dev/mtdblock/1' > /backup/archives/openwrt_jffs2+squashfs-`/bin/date +%m-%d-%Y`.trx
ssh root@192.168.1.254 -p 57600 -C 'dd if=/dev/mtdblock/3' > /backup/archives/openwrt_nvram-`/bin/date +%m-%d-%Y`.bin
/bin/gzip /backup/archives/*.bin
/bin/gzip /backup/archives/*.trx
echo "`date` OpenWrt Done" >> /backup/backup.log

echo "`date` Backup Complete" >> /backup/backup.log

#Email report
echo "Subject: Backup Report" > /backup/email.log
df -h >> /backup/email.log
cat /backup/backup.log >> /backup/email.log
ls -lah /backup/archives >> /backup/email.log
cat /backup/email.log|sendmail myemail@mydomain.net
evilghost is offline   Reply With Quote