Fix for mysql error on saving a new service code.
[openemr.git] / interface / main / backuplog.sh
blob724193f0f0ceffc6183e4825ce6a34aaa225d382
1 #/bin/bash
2 # $1 - mysql user $2 mysql password $3 mysql Database $4 Log backup directory
4 # Create temp tables as that of Eventlog and log_comment_encrypt and api_log
5 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "create table if not exists log_comment_encrypt_new like log_comment_encrypt"
6 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "create table if not exists log_new like log"
7 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "create table if not exists api_log_new like api_log"
8 # Rename the existing tables to backup & New tables to Event tables
9 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "rename table log_comment_encrypt to log_comment_encrypt_backup,log_comment_encrypt_new to log_comment_encrypt"
10 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "rename table log to log_backup,log_new to log"
11 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "rename table api_log to api_log_backup,api_log_new to api_log"
12 # Dump the Backup tables
13 mysqldump -u $1 -p$2 -h $5 --port=$6 --opt --quote-names -r $4 $3 --tables log_comment_encrypt_backup log_backup api_log_backup
14 if [ $? -eq 0 ]
15 then
16 # After Successful dumping, drop the Backup tables
17 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "drop table if exists log_comment_encrypt_backup"
18 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "drop table if exists log_backup"
19 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "drop table if exists api_log_backup"
20 else
21 # If dumping fails, then restore the previous state
22 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "drop table if exists log_comment_encrypt"
23 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "rename table log_comment_encrypt_backup to log_comment_encrypt"
24 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "drop table if exists log"
25 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "rename table log_backup to log"
26 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "drop table if exists api_log"
27 mysql -u $1 -p$2 -h $5 --port=$6 -D $3 -e "rename table api_log_backup to api_log"