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 23:11, 16 March 2018 by Mandala-la (talk | contribs) (fix)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

Needed Software[edit]

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[edit]

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=`whereis tar | cut -d ' ' -f 2`
p7zip_PATH=`whereis 7za | cut -d ' ' -f 2`
SendEmail_PATH=`whereis sendEmail | cut -d ' ' -f 2`
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 after here
if [ ! -d "$DIR" ]; then echo "You MUST change DIR variable. TAR. Visit:";  exit 0; fi
if [ ! -x "$TAR_PATH" ]; then echo "You MUST change TAR_PATH variable. Or install TAR. Visit:"; exit 0; fi
if [ ! -x "$p7zip_PATH" ]; then echo "You MUST change p7zip_PATH variable. Or install p7zip. Visit:"; exit 0; fi
if [ ! -x "$SendEmail_PATH" ]; then echo "You MUST change SendEmail_PATH variable. Or install SendEmail. Visit:"; exit 0; fi
$p7zip_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).