Personally, I have a shell script that runs via root's crontab that backs up my cPanel server nicely... backs up mysql databases to tar.gz files, backs all data (including the mysqlbackups) up to 2nd harddrive (full daily backup into folders for each day) and then does a full daily backup to tape also.
Here are the 3x scripts...
1. fullbackup.sh
Code:
#!/bin/sh
#
# majordomo alias file
# Copyright 2000 Troy P. Bahan
#
# Available from http://www.freebsddiary.org/samples/dump.sh.txt
#
# See http://www.freebsddiary.org/dump-restore.php
#
#Run Disk-to-Disk backup
echo "Beginning backup to internal disk..."
echo " "
/root/tools/backup/backuptodisk.pl
echo " "
echo "Backup to Hard Disk Complete"
echo " "
#Now start Disk-to-Tape backup
echo "Beginning backup to tape..."
echo " "
TARGET=/dev/sa0
FILESYSTEMS=/:/home:/tmp:/usr:/var:
DUMPLEVEL=0
DUMPOPTIONS=au
MTACTION=rewind
MT=/usr/bin/mt
SED=/usr/bin/sed
DUMP=/sbin/dump
SH=/bin/sh
#Rewind the tape
echo "${MT} ${MTACTION}"
${MT} ${MTACTION}
#Do the dump for each file system
for i in `echo $FILESYSTEMS | ${SED} 's/:/ /g'`
do
echo "${DUMP} ${DUMPLEVEL}${DUMPOPTIONS}f ${TARGET} $i"
${DUMP} ${DUMPLEVEL}${DUMPOPTIONS}f ${TARGET} $i
done
#Rewind the tape
echo "${MT} ${MTACTION}"
${MT} ${MTACTION}
${MT} offline
echo "Backups completed, tape rewound and ejected."
exit();
2 - backuptodisk.pl
Code:
#!/usr/bin/perl
# Part of a group of programs to admin a FreeBSD web/email server.
# Do what you want with it, just keep the copyright.
#
# Copyright 2004, Erin Fortenberry
#
# $Id: backup.pl,v 1.2 2004/08/26 21:01:19 erinf Exp $
#
# usage: "scriptname -h"
#
# I use /backup as my backup drive and it is nfs mounted.
# You can remove the compression on this, but it adds alot
# to the backup time so I did not make a switch for it.
#
# The current backup directory it /backup/$hostname/$day.$name.dump.gz
#
# This script does not check to see if the backup directories exist or
# if they have enough space for the dump file.
#
# Requires perl 5.6.1 or newer.
#
use strict;
use warnings;
use Getopt::Std;
use POSIX qw(strftime);
use vars qw($VERSION);
$Getopt::Std::STANDARD_HELP_VERSION = 1;
$VERSION = '1.2';
my @FS = ('/', '/home', '/usr', '/var');
my $day = lc(strftime "%A", localtime);
my $hostname = `/bin/hostname -s`;
my %opt = ('F' => 0, 'd' => 0, 'h' => 0);
my $type;
chomp $hostname;
getopts("Fdh",\%opt);
if ( $opt{h} == 1 ) {
print STDERR << "EOF";
usage: $0 [-hqd]
-h : this (help) message
-d : Dry run, only print what I am going to do
-F : Force full backup {type 0}
example: $0 -h -q -d
EOF
exit(0)
}
if ( $opt{F} == 1 ) {
$type = "0"
} else {
if ($day eq "sunday") {
$type = "0"
} else {
$type = "0"
}
}
foreach (@FS) {
my $name = $_;
if ($name eq '/') {
$name = '/root';
};
$name =~ s/^\///g;
# Unncomment for /backup/$day/$name.dump.gz
my $command = '/sbin/dump -' . $type . ' -auf - ' . $_ . ' |
gzip -q > /backup/' . $day . '/' .
$name . '.dump.gz';
# Put a "#" in front of the next line if you uncomment the last line
# my $command = '/sbin/dump -' . $type . ' -auf - ' . $_ . ' | gzip -q > /backup/' . $hostname .
'/' . $day . '.' . $name . '.dump.gz';
if ($opt{d}) {
print($command . "\n");
} else {
system($command);
};
};
exit(0);
3 - mysqlbackup.sh
Code:
#!/bin/sh
USER=
PASS=
TARGET=/home/horbury/backup_mysql
DUMPPATH=/usr/local/bin
echo "Performing database dumps..."
$DUMPPATH/mysqldump --opt -h localhost -u $USER -p$PASS horbury_dppd06 >$TARGET/dppd06.sql
$DUMPPATH/mysqldump --opt -h localhost -u $USER -p$PASS horbury_icthelpdesk >$TARGET/hesk.sql
$DUMPPATH/mysqldump --opt -h localhost -u $USER -p$PASS horbury_markbook >$TARGET/markbook.sql
$DUMPPATH/mysqldump --skip-opt -h localhost -u $USER -p$PASS horbury_moodle >$TARGET/moodle.sql
$DUMPPATH/mysqldump --opt -h localhost -u $USER -p$PASS horbury_strict >$TARGET/strict.sql
$DUMPPATH/mysqldump --skip-opt -h localhost -u $USER -p$PASS horbury_wb >$TARGET/wb.sql
$DUMPPATH/mysqldump --opt -h localhost -u $USER -p$PASS horbury_mrbs >$TARGET/mrbs.sql
echo "Tarballing succesful dump files..."
tar -czf /home/horbury/backup_mysql/dppd06_sql.tar.gz /home/horbury/backup_mysql/dppd06.sql
tar -czf /home/horbury/backup_mysql/hesk_sql.tar.gz /home/horbury/backup_mysql/hesk.sql
tar -czf /home/horbury/backup_mysql/markbook_sql.tar.gz /home/horbury/backup_mysql/markbook.sql
tar -czf /home/horbury/backup_mysql/moodle_sql.tar.gz /home/horbury/backup_mysql/moodle.sql
tar -czf /home/horbury/backup_mysql/strict_sql.tar.gz /home/horbury/backup_mysql/strict.sql
tar -czf /home/horbury/backup_mysql/wb_sql.tar.gz /home/horbury/backup_mysql/wb.sql
tar -czf /home/horbury/backup_mysql/mrbs_sql.tar.gz /home/horbury/backup_mysql/mrbs.sql
echo "Deleting original dump files, leaving only tarballs..."
rm /home/horbury/backup_mysql/dppd06.sql
rm /home/horbury/backup_mysql/hesk.sql
rm /home/horbury/backup_mysql/markbook.sql
rm /home/horbury/backup_mysql/moodle.sql
rm /home/horbury/backup_mysql/strict.sql
rm /home/horbury/backup_mysql/wb.sql
rm /home/horbury/backup_mysql/mrbs.sql
echo "MySQL Backups completed."
exit();
Cronjob runs mysqlbackup.sh, then fullbackup.sh (which calls backuptodisk.pl) - these run in the early hours of the morning. All I have to do is remember to change tapes each evening before I leave work.