This morning I was looking at automating its backups and found this script on the forums. I did change one or two small things in the script, mostly just two rm -d commands with rm -rf.
#!/bin/sh
# this is script for remote backup MukroTik Dude database
# requires: sh, awk, wget
#
# result XML file will be placed in "dude-backup-files" directory (if you don't change this value)
#
# by mr.Z ([email protected])
# ver 1.1p, 2009
##############################################################################################
# Edit 5 lines below for access to your server and set work/backup directory. USE ABSOLUTLEY PATH FOR DIRECTORIES
server=x.x.x.x # enter server name or IP address
user=admin # enter admin user name
password= # enter admin password
backupdir=/home/wayne/dude-backup/data # set directoryfor backup files
workdir=/home/wayne/dude-backup/work # set directory for temporary files (ATTENTION! AFTER WORK IT WILL BE DELETED)
# OPTIONALLY you can set server port and log file
serverport=80
logfile=$backupdir/log.txt
##############################################################################################
# DO NOT EDIT ANY LINES BELOW
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
# creating directories for work and backup file
if [ ! -e "$workdir" ]
then
mkdir -p "$workdir"
fi
if [ ! -e "$backupdir" ]
then
mkdir -p "$backupdir"
fi
if [ ! -e "$backupdir/old" ]
then
mkdir -p "$backupdir/old"
fi
today=`date +%Y.%m.%d` #setting today date (need for getting file from server)
serverfilename=backupbackup-$today.xml #setting file name on server
backupname=dude-backup-$today.xml
echo "-------------------------------------------------------
Starting new backup procedure at $today
" >> $logfile
# moving last backup to old directory
mv $backupdir/*backup* $backupdir/old 2> /dev/null
# getting file from dude server
echo "Authorizing..."
wget --cookies=on --keep-session-cookies --save-cookies=$workdir/cookie.txt --progress=dot:mega "http://$server:$serverport/dude/main.html?process=login&user=$user&password=$password" -O $workdir/page1.html 2>> $logfile
echo "Please wait, downloading backup XML file. This may take long time..."
wget --cookies=on --load-cookies=$workdir/cookie.txt --progress=dot:mega "http://$server:$serverport/dude/$serverfilename?page=savefile&download=yes" -O $backupdir/$backupname 2>> $logfile
# cleaning
echo "Cleaning..."
rm -rf $workdir/*
#rm -d $workdir
# checking for new backup file and cleaning old
if [ `du $backupdir/$backupname | awk -F" " '{print($1)}'` -gt 0 ]
then
rm -rf $backupdir/old/*
#rm -d $backupdir/old
echo "All done."
else
rm -f $backupdir/$backupname
echo "Backup failed! (see log.txt in $backupdir direectory)"
echo "Backup failed!" >> $logfile
fi
echo "
Backup procedure finished.
-------------------------------------------------------
" >> $logfile
exit
ไม่มีความคิดเห็น:
แสดงความคิดเห็น
หมายเหตุ: มีเพียงสมาชิกของบล็อกนี้เท่านั้นที่สามารถแสดงความคิดเห็น