Automatic data backup

To schedule automatic data backup, follow these steps:


You should keep one usb drive permanently connected to Saleculator.

Ctrl+Alt+F1
1. Enter the below command:

nano /opt/backup.sh

2. Copy paste the below code to the editor

#!/bin/bash
set -e
ignore_tables=(
DELIVERYORDERS
CALLS
TICKETLINES
TAXLINES
TICKETS
PAYMENTS
RECEIPTS
SHAREDTICKETS
STOCKDIARY
)
ignore_string=" "
ignore_name=""
for i in "${ignore_tables[@]}"
do
        ignore_name=" --ignore_table=SALECULATOR.${i}"
        ignore_string="${ignore_string}${ignore_name}"
done
if grep -qs "/flash" /proc/mounts; then
   umount /flash
fi
##For table checking and optimizing uncomment below 2 commands
#mysqlcheck --user=root --password=password SALECULATOR --check-only-changed --auto-repair
#mysqlcheck --user=root --password=password SALECULATOR --optimize
if mount /dev/sdb1 /flash ; then
  #Delete backups older than 7 days
  find /flash -mtime +7 -type f -delete
  mysqldump --user=root --password=password SALECULATOR $ignore_string | bzip2 > /flash/backup$(date +%Y%m%d%H%M).bz2
  umount /flash
fi

This script exclude transactional tables from automatic backup. You can change the ignore_tables section to add or remove tables.
3. Press CTRL+X, Y, Enter to save the file

4. Enter the below command

chmod +x /opt/backup.sh

5. Execute below command to make sure backup is working

/opt/backup.sh

5. Enter the below command

crontab -e

6. Add the below line at the end

30 2 * * * /opt/backup.sh

This is will backup data everyday at 2.30am. Below are some examples to schedule at other intervals:
Every Saturday at 2.30am:
2 * * 6 /opt/backup.sh
First of every month at 12.00am:
0 0 1 * * /opt/backup.sh
On the 1st of Jan, Apr, Jul and Oct at 03:30:
30 03 01 Jan,Apr,Jul,Oct * /opt/backup.sh

7. Press CTRL+X, Y, Enter to save the file

0 Comments

Leave a Reply

Arrow-up