Another backup solution

Because of not finding a backup solution that fit my needs i've take some pieces from other scripts added some of my own and rewrite it to this one.

How it works:
The script makes a backup of the MySQL database in separate files (each DB has it own file) every 4 hours by using a cronjob, these files are stored in a local directory.

When finished the DB backup and the ISPconfig (Website) backup are copied to a FTP server, to prevent unneccessary load and bandwidth use the backup of the websites is copied once a day during the night (ISPconfig makes 1 backup at 0:30 so extra copies are not needed)

What has changed?
The MySQL backup will now keep 7 day en 3 sunday backups, then the oldest will be deleted in the local backup.
The backup directory structure is changed, it will now create a time directory inside the date directory.
Added echo's for screen output when running the script in screen.

For those who are interested, i did a complete rewrite of the wdbackup.sh and create 2 backupscripts, 1 for an external (your own?) FTP server and 1 for an internal FTP server (hired from or provided by the server hoster)

Short description:

Using an internal FTP backupserver.
This script will copy the websites backup files at 02.00H, the MySQL databases every 4 hours starting at 02.00H and the ISPconfig website and SQL database at 14.00H and 22:00H to an internal FTP server.
The MySQL backup databases on the local server will be purged every 7 days except the sunday backup, this database will be purged every 4 weeks.

Using an external FTP backupserver.
This script will copy the websites at 02.00H, the MySQL databases every 4 hours starting at 02.00H and the ISPconfig website and SQL database at 14.00H and 22:00H to a external FTP server of your choice. Every MySQL backup is overwritten after 24 hours, the websites backup is overwritten after 2 days. The MySQL backup databases on the local server will be purged every 7 days exept the sunday backup, this database will be purged every 4 weeks.

The backup of ISPconfig runs at 14:00H and 22:00H, in the notification e-mail backups which are not scheduled to run are mentioned as: No Backup scheduled.

I've found a little "bug" in the backupscript, the backup of ISPconfig is called twice in the script, when it runs e.g. at 14:00 hours the second part which is scheduled at 22:00 will give the message: No Backup scheduled. (and at 22:00 it will give the same message)

If you have a error like [ 92 : unexpected error ]. The problem maybe comes from Dash. In debian /bin/sh is a symlink to /bin/dash, however we need /bin/bash, not /bin/dash. But if you have ISPconfig on your server you have reconfigure Dash.( If you don't do this, the ISPConfig installation fail).

If you have a error run this command in shell

#bash -x your_script

If it's works run this command in shell

#dpkg-reconfigure dash

Use dash as the default system shell (/bin/sh)? <-- No

A other solution is to change in the script the first line #!/bin/sh to #!/bin/bash

If you would like to test the script now ( all backups) at 21:25 and not at 21H you can change this line

./wdbackup.sh: line 228: -u: command not found
./wdbackup.sh: line 228: -u: command not found
./wdbackup.sh: line 228: -u: command not found
./wdbackup.sh: line 228: -u: command not found
./wdbackup.sh: line 228: -u: command not found