PHP7 Project. Commit 20. Fixes in calendar module.
[openemr.git] / interface / main / backuplog.sh
blob5a7174c93838899fccd948afdeadf4d8b53b3787
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
5 mysql -u $1 -p$2 -D $3 -e "create table if not exists log_comment_encrypt_new like log_comment_encrypt"
6 mysql -u $1 -p$2 -D $3 -e "create table if not exists log_new like log"
7 # Rename the existing tables to backup & New tables to Event tables
8 mysql -u $1 -p$2 -D $3 -e "rename table log_comment_encrypt to log_comment_encrypt_backup,log_comment_encrypt_new to log_comment_encrypt"
9 mysql -u $1 -p$2 -D $3 -e "rename table log to log_backup,log_new to log"
10 # Dump the Backup tables
11 mysqldump -u $1 -p$2 --opt --quote-names -r $4 $3 --tables log_comment_encrypt_backup log_backup
12 if [ $? -eq 0 ]
13 then
14 # After Successful dumping, drop the Backup tables
15 mysql -u $1 -p$2 -D $3 -e "drop table if exists log_comment_encrypt_backup"
16 mysql -u $1 -p$2 -D $3 -e "drop table if exists log_backup"
17 else
18 # If dumping fails, then restore the previous state
19 mysql -u $1 -p$2 -D $3 -e "drop table if exists log_comment_encrypt"
20 mysql -u $1 -p$2 -D $3 -e "rename table log_comment_encrypt_backup to log_comment_encrypt"
21 mysql -u $1 -p$2 -D $3 -e "drop table if exists log"
22 mysql -u $1 -p$2 -D $3 -e "rename table log_backup to log"