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

Very high compression ratio file archiver
A GNU file archiving program (Should be preinstalled virtually everywhere)
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.


This should be the content:

### Change this:
### Facultatif change :
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:"
if [ ! -x $7ZA_PATH ]; then
 echo "You MUST change 7ZA_PATH variable. Or install p7zip. Visit:"
if [ ! -x $SendEmail_PATH ]; then
 echo "You MUST change SendEmail_PATH variable. Or install SendEmail. Visit:"
$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:

sevenzp= (just the password at the end)
/usr/bin/sendEmail -f $

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

Now you should test the script manually:


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


You can edit your crontab with this command:

crontab -e

Now add this line somewhere:

40 0  * * 4 cd /home/znc; ./ >/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;         ./ >/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).