To create new wiki account, please join us on #znc at Libera.Chat and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.
ZNC Backup
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=`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: http://wiki.znc.in/index.php?title=ZNC_Backup"; exit 0; fi 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"; exit 0; fi if [ ! -x "$p7zip_PATH" ]; then echo "You MUST change p7zip_PATH variable. Or install p7zip. Visit: http://wiki.znc.in/index.php?title=ZNC_Backup"; exit 0; 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"; exit 0; fi $TAR_PATH -cvf $DATEI1 $DIR $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:
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
).