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
DATEI1=$(date +%Y-%m-%d)_znc_backup.tar
DATEI2=$(date +%Y-%m-%d)_znc_backup.tar.7z
DATUM=$(date +%Y-%m-%d)
USER=znc
sevenzp=a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -mhe=on -p=Pa7Sw0r7
MAILADRESSE1=deine{at}email.de
DIR=/home/$USER/.znc
/usr/bin/tar -cvf $DATEI1 $DIR
/usr/bin/7za $sevenzp $DATEI2 $DATEI1
/usr/bin/sendEmail -f $USER@your.host -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).