Re: How to: Cron Backup

Home Page Forums Network Management ZeroShell [SOLVED] Cron Backup Re: How to: Cron Backup

#51725

Ihyae
Member

Hi (sorry for my poor English!),
this script it’s a replace of the original script.
But given that the scripts are reset to (re) boot I had to copy the script in a path which would not be reset every time you start! (eg. /Database).
As for the script I scheduled a cron once a week.
In the example I gave above, /mnt/backup is just a pendrive mounted in /mnt/backup but that is not binding.
For example, you could replace /mnt/backup with a remote destination … maybe on another server in ssh (after generating a key pair (not having to enter the pass from time to time)) by changing the script this way.


#!/bin/sh
BN=ZeroShell-`%d %b %Y %H:%M`.bak
source /etc/kerbynet.conf
function UMOUNT () {
cd /
umount $MP/$DB.AUX 2> /dev/null
if [ "$ALREADYMOUNTED" == No ] ; then
umount "$MP" && rmdir "$MP"
fi
}
function ERROR () {
cd /
echo ERROR > "$MP/$DB/.settings/LastBackup"
UMOUNT
exit 1
}
DEV="$1"
DB="$2"
COMPRESSED="$3"
WOLOGS="$4"
[ -z "$DEV" -o -z "$DB" ] && exit 1
$SCRIPTS/umountstorage >/dev/null
NODEV=${DEV:2}
LINE=`df -T -P | grep "$NODEV "`
if [ -z "$LINE" ] ; then
MP=/storage/`echo $DEV | sed -e "s///_/g"`;
mkdir -p "$MP"
mount -o rw "$DEV" "$MP" || exit 1
if [ -r /$MP/$DB.AUX ] ; then
if ! mount -oloop $MP/$DB.AUX /$MP/$DB ; then
UMOUNT
exit 2
fi
fi
ALREADYMOUNTED=No
else
MP=`echo $LINE | cut -f7 -d' '`
mount -oremount,rw "$MP" || exit 1
ALREADYMOUNTED=Yes
if [ -r /$MP/$DB.AUX ] ; then
if ! mount -oloop $MP/$DB.AUX /$MP/$DB ; then
UMOUNT
exit 2
fi
fi
fi
cd "$MP/$DB"
if ! [ -d .settings ]; then
UMOUNT
exit 3
fi
if [ "$WOLOGS" = Yes ] ; then
EXCLUDE='--exclude LOG'
else
EXCLUDE=''
fi
if [ "$COMPRESSED" == Yes ] ; then
for N in `seq 1 100` ; do
echo "$N BACKUP $DEV $DB `date` ================================================================================================" | ssh root@192.168.0.10 "cat >> /remote/destination/$BN"
done
tar cfzv - --exclude var/register/system/havp/tmp/* $EXCLUDE . | uuencode /dev/stdout | ssh root@192.168.0.10 "cat >> /remote/destination/$BN" || ERROR
else
tar cf - --exclude var/register/system/havp/tmp/* $EXCLUDE . || ERROR
fi
date +"%d %b %Y %H:%M" > "$MP/$DB/.settings/LastBackup"
UMOUNT

Another option I considered was to use samba .. up to beta 12, you can use this version: http://www.orquideadesign.com/SMB12_beta1.tar.bz2
details at this link: http://www.zeroshell.net/eng/forum/viewtopic.php?t=2209

Let me know if you need help;)
bye bye,
Dennis