[BlueOnyx:19654] Re: Automated Server Backup
Jeff Folk
jfolk at qzoneinc.com
Fri Jun 3 12:32:31 -05 2016
On Jun 3, 2016, at 10:55 AM, Richard Barker wrote:
> Hey Jeff,
> Thanks if you don't mind yes I would
> RC
> --
The ftp functions.
function ftptest() {
if test $TARGET; then
plugin preftp
if test $TARGETDIR; then
FTPPREPARE1="cd $TARGETDIR"
fi
if test $TARGET && test $TARGETUSER && test "$TARGETPASS"; then
echo -n "$(date +%T) > Testing connection to $TARGET... "
ftp -i -n -v $TARGET $TARGETPORT 1> $WORKDIR/logs/output-ftptest.log 2> $WORKDIR/logs/errors-ftptest.log <<!EOF!
user $TARGETUSER $TARGETPASS
$FTPPREPARE1
mkdir $SOURCE.bak2
mkdir $SOURCE.bak1
mkdir $SOURCE.bak0
mkdir $SOURCE.bak
mkdir $SOURCE
cd $SOURCE.bak
put readme.txt ftptest.txt
get ftptest.txt
quit
!EOF!
if test -s $WORKDIR/ftptest.txt; then
echo "ok"
rm $WORKDIR/ftptest.txt
cd $WORKDIR/data
ftpbackup
else
echo "not ok"
if test $TARGETRETRYCONNECT -gt 0; then
echo "$(date +%T) > Trying again in 10 minutes..."
TARGETRETRYCONNECT=`expr $TARGETRETRYCONNECT - 1`
sleep 10m
ftptest
else
if test $DELBACKUP = "1"; then
DELBACKUP="0"
fi
errormsg "echo -e \"Failed to transfer test-file to $TARGET!\nCheck username, password and hostname of the target machine!\nYou might find more information in your logs, see\n$WORKDIR/logs/output-ftptest.log and/or\n$WORKDIR/logs/errors-ftptest.log\nYou can find the complete backup on this RaQ under $WORKDIR/data\""
fi
fi
else
if test $DELBACKUP = "1"; then
DELBACKUP="0"
fi
echo "not ok"
errormsg "echo -e \"Failed to transfer test-file to $TARGET!\nUsername, password or hostname are empty!\nYou can find the complete backup on this RaQ under $WORKDIR/data\""
fi
else
echo "$(date +%T) > FYI: No transfer of the backup to another server!"
fi
}
function ftpbackup() {
echo "FIRST-FILE-OK" > $WORKDIR/data/ftptest1.txt
echo "LAST-FILE-OK" > $WORKDIR/data/ftptest2.txt
echo -n "$(date +%T) > Transferring backup to $TARGET... "
ftp -i -n -v $TARGET $TARGETPORT 1> $WORKDIR/logs/output-ftptransfer.log 2> $WORKDIR/logs/errors-ftptransfer.log <<!EOF!
user $TARGETUSER $TARGETPASS
$FTPPREPARE1
cd $SOURCE.bak2
mdelete *
cd ..
rmdir $SOURCE.bak2
rename $SOURCE.bak1 $SOURCE.bak2
rename $SOURCE.bak0 $SOURCE.bak1
rename $SOURCE.bak $SOURCE.bak0
rename $SOURCE $SOURCE.bak
mkdir $SOURCE
cd $SOURCE
ascii
put ftptest1.txt testftp1.txt
binary
mput *.gz*
ascii
$FTPASCII0
$FTPASCII1
$FTPASCII2
put ftptest2.txt testftp2.txt
get testftp1.txt
get testftp2.txt
quit
!EOF!
if test $? = "0" && test -s $WORKDIR/data/testftp1.txt && test -s $WORKDIR/data/testftp2.txt; then
echo "ok"
if test $DETAILWHEN = "always" || test $DETAILWHEN = "$(date +%w)" || test $DETAILWHEN = "$(date +%d)"; then
echo -n "$(date +%T) > Getting listing from $TARGET... "
ftp -i -n -v $TARGET $TARGETPORT 1> $WORKDIR/logs/output-ftptargetlisting.log 2> $WORKDIR/logs/errors-ftptargetlisting.log<<!EOF!
user $TARGETUSER $TARGETPASS
$FTPPREPARE1
cd $SOURCE
ls
quit
!EOF!
if test $? = "0"; then
echo "ok"
else
echo "not ok"
errormsg "cat $WORKDIR/logs/errors-ftptargetlisting.log"
fi
showdetails "cat $WORKDIR/logs/output-ftptargetlisting.log"
fi
else
echo "not ok"
if test $DELBACKUP = "1"; then
DELBACKUP="0"
fi
if test -s $WORKDIR/data/testftp1.txt && test ! -s $WORKDIR/data/testftp2.txt; then
errormsg "echo -e \"Failed to transfer the complete backup to $TARGET!\nFirst file was transferred, last file not.\nMaybe you don't have enough quota on $TARGET?\nYou can find the complete backup on this RaQ under $WORKDIR/data\n$LONGLINE\nYour logfile:\"; cat $WORKDIR/logs/errors-ftptransfer.log; cat $WORKDIR/logs/output-ftptransfer.log;"
else
errormsg "echo -e \"Failed to transfer the backup to $TARGET!\nMaybe your connection was lost since raqbackup.sh tested your connection.\nYou can find the complete backup on this RaQ under $WORKDIR/data\n$LONGLINE\nYour logfile:\"; cat $WORKDIR/logs/errors-ftptransfer.log; cat $WORKDIR/logs/output-ftptransfer.log;"
fi
fi
plugin postftp
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.blueonyx.it/pipermail/blueonyx/attachments/20160603/c395756c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4109 bytes
Desc: not available
URL: <http://mail.blueonyx.it/pipermail/blueonyx/attachments/20160603/c395756c/attachment.p7s>
More information about the Blueonyx
mailing list