To create new wiki account, please join us on #znc at freenode and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.

ZNC Backup

From ZNC
Revision as of 22:38, 20 April 2012 by McDeffice (talk) (Backup Script)
Jump to: navigation, search

Here is described how you can get your ZNC data dir emailed to you once per week.

Needed Software

p7zip 
Very high compression ratio file archiver
tar 
A GNU file archiving program (Should be preinstalled virtually everywhere)
SendEmail 
http://caspian.dotconf.net/menu/Software/SendEmail/ (I didn't find this in any linux distro so far)

Backup Script

After the installation a small script is created in the user's home dir.

vi znc-backup.sh

This should be the content:

#!/bin/bash
### Change this:
USER=znc
PASSWORD=Pa7Sw0r7
MAILADRESSE1=deine{at}email.de
YOUREHOST=MyDomain.org
### Facultatif change :
DIR=/home/$USER/.znc
TAR_PATH=`/usr/bin/whereis tar`
7ZA_PATH=`/usr/bin/whereis 7za`
SendEmail_PATH=`/usr/bin/whereis sendEmail`
DATEI1=$(date +%Y-%m-%d)_znc_backup.tar
DATEI2=$(date +%Y-%m-%d)_znc_backup.tar.7z
DATUM=$(date +%Y-%m-%d)
sevenzp="a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -mhe=on -p=$PASSWORD"
### no Change aftere here
if [ ! -x $TAR_PATH ]; then
 echo "You MUST change TAR_PATH variable. Or install TAR. Visit: http://wiki.znc.in/index.php?title=ZNC_Backup"
fi
if [ ! -x $7ZA_PATH ]; then
 echo "You MUST change 7ZA_PATH variable. Or install p7zip. Visit: http://wiki.znc.in/index.php?title=ZNC_Backup"
fi
if [ ! -x $SendEmail_PATH ]; then
 echo "You MUST change SendEmail_PATH variable. Or install SendEmail. Visit: http://wiki.znc.in/index.php?title=ZNC_Backup"
fi
$TAR_PATH -cvf $DATEI1 $DIR
$7ZA_PATH $sevenzp $DATEI2 $DATEI1
$SendEmail_PATH -f $USER@$YOUREHOST -u ZNC-Backup-$DATUM -m ZNC Backup from $DATUM -a $DATEI2 -t $MAILADRESSE1
rm -f $DATEI1 $DATEI2

These lines should be customized:

USER=
sevenzp= (just the password at the end)
MAILADRESSE1=
/usr/bin/sendEmail -f $USER@your.host

Please notice the line 7za $sevenzp $DATEI2 $DATEI1. With some distros the 7zip binary is called 7z instead of 7za. Change this if appropriate.

If you don't have 1 GB of RAM, you might have to lower the compression rate. This is done with the parameter -mx=X in the sevenzp=...-line. X is the compression rate, which might be between 0 and 9 where 0 means no compression.

Now the script must be made executable:

chmod a+x znc-backup.sh

Now you should test the script manually:

./znc-backup.sh

If everything works fine, we can now set up the crontab entry, else you have to find and fix the error.

Crontab

You can edit your crontab with this command:

crontab -e

Now add this line somewhere:

40 0  * * 4 cd /home/znc; ./znc-backup.sh >/dev/null 2>&1

My crontab looks like this:

* * * * *   cd /home/znc/znc/bin; ./znc >/dev/null 2>&1
40 0  * * 4 cd /home/znc;         ./znc-backup.sh >/dev/null 2>&1

There is a check if ZNC is still running caried out every minute. The second line starts the backup script once per week on Thursday (4) at 0:40 am (40 0).