[mythtv-users] I am an idiot - deleted everything without DB backup - a question...

Jon jon.the.wise.gdrive at gmail.com
Tue Sep 11 14:28:16 UTC 2007


On Sep 11, 2007, at 5:44 AM, Mitch Gore wrote:

>
>
> On 9/11/07, Bruce Nordstrand <brucen at ksl.com.au> wrote:
>
>
> Jon wrote:
> >> Oh, and I have to get myself a backup command to automatically  
> put a
> >> backup somewhere else on the network. That or don't do Myth  
> rebuilds
> >> when I haven't had enough sleep....
> >>
>
>
>
> Here is mine.  Put in /etc/cron.daily/
> ---------------------------------------------------------------------- 
> ------------------
> FN=mythtv_backup-$(date +%Y-%m-%d_%H:%M).sql
> DIR=/home/myth/.mythbackups
>
> mysqldump -u mythtv -pmythtv mythconverg -c > $DIR/$FN
>
> # bzip our db backup so it takes alot less space
> bzip2 $DIR/$FN
>
> #delete any backup files that status haven't changed for over 3 days.
> rm $(find $DIR -ctime +3 -name "mythtv_backup*")
> ---------------------------------------------------------------------- 
> -----------------
>
> This keeps 3 but can be modified easily.
>

Not bad, I like how easy that is to change. Here's mine:

---------
Crontab
---------
30 1 * * * /myth2/db/backup.pl

----------
/myth2/db/backup.pl
----------

#!/usr/bin/perl
$backuplog = "/var/log/mythtv/backup.log";
$filename = "/myth2/db/mythtv_backup_".`date | cut -c 1-3`;
$command = "mysqldump -u mythtv -pmythtv mythconverg -c >".$filename;
$date = `date`;
`echo "Dumping database to $filename on $date" >> $backuplog`;
`$command`;
`echo "Optimizing database" >> $backuplog`;

$OPT_MYTHDB='/usr/share/doc/mythtv-0.20.2/contrib/optimize_mythdb.pl';
$LOG='/var/log/mythtv/optimize_mythdb.log';
$date = `date`;
`echo "Started $OPT_MYTHDB on $date" >> $LOG`;
`$OPT_MYTHDB >> $LOG`;
$date = `date`;
`echo "Finished $OPT_MYTHDB on $date" >> $LOG`;

----------
And again, this time with comments:
----------

#!/usr/bin/perl
$backuplog = "/var/log/mythtv/backup.log";  <-- I keep a log of every  
time it runs
$filename = "/myth2/db/mythtv_backup_".`date | cut -c 1-3`; <---this  
names the file with the day of the week
$command = "mysqldump -u mythtv -pmythtv mythconverg -c >".$filename;  
<---actual command to backup the database
$date = `date`; <--- date for the next line... I probably could do  
this differently, but this works
`echo "Dumping database to $filename on $date" >> $backuplog`; <---  
this is appending to my log the date and an entry that the command  
was run
`$command`; <---backup the db
`echo "Optimizing database" >> $backuplog`; <-- telling the log I'm  
going to optimize

The following optimizes the database:

$OPT_MYTHDB='/usr/share/doc/mythtv-0.20.2/contrib/optimize_mythdb.pl';
$LOG='/var/log/mythtv/optimize_mythdb.log';
$date = `date`;
`echo "Started $OPT_MYTHDB on $date" >> $LOG`;
`$OPT_MYTHDB >> $LOG`;
$date = `date`;
`echo "Finished $OPT_MYTHDB on $date" >> $LOG`;

so there you have it.... it could definately be made more simple, but  
that's how I do it.

~Jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mythtv.org/pipermail/mythtv-users/attachments/20070911/3504aa7d/attachment.htm 


More information about the mythtv-users mailing list