Backup ABillS

I will describe an example of backup ABillS billing system.

Create a directory for backup copies of the database if it is not created:

mkdir /usr/abills/backup
chown www-data:www-data /usr/abills/backup

I note that the database is also backed up by “periodic monthly” and files older than 30 days are cleared. But if you wish, you can disable adding “SKIP_MODULES”, for example:

/usr/abills/libexec/periodic monthly SKIP_MODULES=backup

To manually create a backup of the database, you can run it (the script also deletes files older than 30 days):

/usr/abills/libexec/periodic backup
/usr/abills/libexec/periodic backup DEBUG=2

A manual backup of the ABillS database can also be made via the web interface by opening – “Settings” – “Others” – “Database archiving”.

It is better not to run this command on high-load systems, since the tables are locked and there may be unpredictable problems, I have an access server because of this, or manually start mysqldump with a single-transaction key.

Since “periodic monthly” makes copies of the database, there is no point in adding the “periodic backup” command to cron.

For large databases, I recommend setting up MySQL replication and already backing up from the second database, and disabling backups on the main server.

If the database backup files are not being created, then the path to mysqldump may not be indicated, it can be specified in the “Settings” – “Other” – “Paths” menu, also in the files:
/usr/abills/abills/programs
/usr/abills/Abills/templates/programs.tpl
or create a symbolic link in /usr/local/bin/mysqldump

You can restore the database from a backup copy as follows:

cd /usr/abills/backup
gzip -d stats-xxxx-xx-xx.sql.gz
mysql -D abills < stats-xxxx-xx-xx.sql

Through the utility “pv” you can see the import process:

apt install pv
pv stats-`date +%Y-%m-%d`.sql | mysql -u root -D abills

You can also make a copy of the billing directory and other important directories, using nice and ionice I lowered the disk and CPU usage priority so as not to affect server performance. At the end, the command deletes copies older than 4 days, if the base is large, it is better to exclude the /usr/abills/backup directory, for example, I wrote this script:

#!/bin/bash
mkdir /backup/data/`date +%Y-%m-%d`-abills
cd /backup/data/`date +%Y-%m-%d`-abills

nice -n 19 ionice -c2 -n7  mysqldump --single-transaction -R -h localhost -u root -p abills | gzip -c > /backup/data/`date +%Y-%m-%d`-abills/abills_`date +%Y-%m-%d`.sql.gz
nice -n 19 ionice -c2 -n7 tar -cvjf /backup/data/`date +%Y-%m-%d`-abills/etc_`date +%Y-%m-%d`.tar.bz2 /etc/
nice -n 19 ionice -c2 -n7 tar -cvjf /backup/data/`date +%Y-%m-%d`-abills/www_`date +%Y-%m-%d`.tar.bz2 /var/www/
nice -n 19 ionice -c2 -n7 tar -cvjf /backup/data/`date +%Y-%m-%d`-abills/abills_`date +%Y-%m-%d`.tar.bz2 /usr/abills/
nice -n 19 ionice -c2 -n7 tar -cvjf /backup/data/`date +%Y-%m-%d`-abills/usr_local_`date +%Y-%m-%d`.tar.bz2 /usr/local/
nice -n 19 ionice -c2 -n7 tar -cvjf /backup/data/`date +%Y-%m-%d`-abills/scripts_`date +%Y-%m-%d`.tar.bz2 /backup/scripts/
nice -n 19 ionice -c2 -n7 tar -cvjf /backup/data/`date +%Y-%m-%d`-abills/tftp_`date +%Y-%m-%d`.tar.bz2 /srv/tftp/

iptables-save > /backup/data/`date +%Y-%m-%d`-abills/iptables_`date +%Y-%m-%d`.dump

# Delete old backups
nice -n 19 ionice -c2 -n7 find /backup/data/ -type d -mtime +3 -exec rm -rfv {} \;

See also my articles:
Install and configure ABillS
Installing and Configuring fsbackup
Import and export MySQL databases
Configuring replication in MySQL
Using and configuring CRON

Leave a comment

Leave a Reply

Discover more from IT Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading