Merge pull request #1240 from woogerboy21/db_backup_scripts
Update DB Scripts
This commit is contained in:
commit
aa540f7968
9 changed files with 115 additions and 4 deletions
BIN
servatrice/scripts/File.History
Normal file
BIN
servatrice/scripts/File.History
Normal file
Binary file not shown.
47
servatrice/scripts/db_backup_all
Normal file
47
servatrice/scripts/db_backup_all
Normal file
|
@ -0,0 +1,47 @@
|
|||
#!/bin/bash
|
||||
set -u
|
||||
set -e
|
||||
SLEEPTIME=5
|
||||
SQLCONFFILE="./mysql.cnf" #set this to the path that contains the mysql.cnf file
|
||||
LOGAPPENDDATE=`date +%m%d%Y`
|
||||
EXPIRATION=`date +%m%d%Y -d "-3 days"`
|
||||
DBNAME="servatrice"
|
||||
APPNAME="servatrice"
|
||||
ROOTFOLDER="./backups" #set this to the root path you want backups to be stored in
|
||||
BACKUPDIR="$ROOTFOLDER/$LOGAPPENDDATE/db/$APPNAME"
|
||||
TABLES=(
|
||||
"cockatrice_users"
|
||||
"cockatrice_decklist_files"
|
||||
"cockatrice_replays"
|
||||
"cockatrice_buddylist"
|
||||
"cockatrice_ignorelist"
|
||||
"cockatrice_bans"
|
||||
"cockatrice_sessions"
|
||||
"cockatrice_decklist_folders"
|
||||
"cockatrice_replays_access"
|
||||
"cockatrice_games"
|
||||
"cockatrice_games_players"
|
||||
"cockatrice_uptime"
|
||||
"cockatrice_schema_version"
|
||||
"cockatrice_servermessages"
|
||||
"cockatrice_servers"
|
||||
"cockatrice_news"
|
||||
"cockatrice_rooms"
|
||||
"cockatrice_rooms_gametypes"
|
||||
)
|
||||
|
||||
PROCESSNAME="mysqldump"
|
||||
if [ "$(pgrep $PROCESSNAME)" == "" ];
|
||||
then
|
||||
[ ! -d $BACKUPDIR ] && mkdir -p $BACKUPDIR/
|
||||
for TABLENAME in "${TABLES[@]}"
|
||||
do
|
||||
BACKUPFILE="$BACKUPDIR/$APPNAME.$TABLENAME.sql.$LOGAPPENDDATE"
|
||||
echo "Backing up DB Table [$TABLENAME]"
|
||||
ionice -c3 nice -n19 mysqldump --defaults-file=$SQLCONFFILE $DBNAME $TABLENAME > $BACKUPFILE
|
||||
sleep $SLEEPTIME
|
||||
done
|
||||
rm -rf "$ROOTFOLDER/$EXPIRATION/"
|
||||
else
|
||||
echo "Backup in progress, aborting"
|
||||
fi
|
53
servatrice/scripts/db_restore_all
Normal file
53
servatrice/scripts/db_restore_all
Normal file
|
@ -0,0 +1,53 @@
|
|||
#!/bin/bash
|
||||
set -u
|
||||
set -e
|
||||
SLEEPTIME=5
|
||||
SQLCONFFILE="./mysql.cnf" #set this to the path that contains the mysql.cnf file
|
||||
LOGAPPENDDATE=`date +%m%d%Y`
|
||||
EXPIRATION=`date +%m%d%Y -d "-3 days"`
|
||||
DBNAME="servatrice"
|
||||
APPNAME="servatrice"
|
||||
ROOTFOLDER="./backups" #set this to the root path that contains the backup files
|
||||
BACKUPDIR="$ROOTFOLDER/$LOGAPPENDDATE/db/$APPNAME"
|
||||
TABLES=(
|
||||
"cockatrice_users"
|
||||
"cockatrice_decklist_files"
|
||||
"cockatrice_replays"
|
||||
"cockatrice_buddylist"
|
||||
"cockatrice_ignorelist"
|
||||
"cockatrice_bans"
|
||||
"cockatrice_sessions"
|
||||
"cockatrice_decklist_folders"
|
||||
"cockatrice_replays_access"
|
||||
"cockatrice_games"
|
||||
"cockatrice_games_players"
|
||||
"cockatrice_uptime"
|
||||
"cockatrice_schema_version"
|
||||
"cockatrice_servermessages"
|
||||
"cockatrice_servers"
|
||||
"cockatrice_news"
|
||||
"cockatrice_rooms"
|
||||
"cockatrice_rooms_gametypes"
|
||||
)
|
||||
|
||||
PROCESSNAME="mysqldump"
|
||||
if [ "$(pgrep $PROCESSNAME)" == "" ];
|
||||
then
|
||||
[ ! -d $BACKUPDIR ] && mkdir -p $BACKUPDIR/
|
||||
for TABLENAME in "${TABLES[@]}"
|
||||
do
|
||||
BACKUPFILE="$BACKUPDIR/$APPNAME.$TABLENAME.sql.$LOGAPPENDDATE"
|
||||
if [ -f "$BACKUPFILE" ]
|
||||
then
|
||||
echo "Restoring up DB Table [$TABLENAME]"
|
||||
ionice -c3 nice -n19 mysql --defaults-file=$SQLCONFFILE $DBNAME < $BACKUPFILE
|
||||
sleep $SLEEPTIME
|
||||
else
|
||||
echo "Missing backup file [$$TABLENAME]"
|
||||
sleep $SLEEPTIME
|
||||
fi
|
||||
done
|
||||
rm -rf "$ROOTFOLDER/$EXPIRATION/"
|
||||
else
|
||||
echo "Restore in progress, aborting"
|
||||
fi
|
3
servatrice/scripts/info_db_tablesize
Normal file
3
servatrice/scripts/info_db_tablesize
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
SQLCONFFILE="./mysql.cnf" #set this to the path that contains the mysql.cnf file
|
||||
mysql --defaults-file=$SQLCONFFILE -e 'SELECT table_name AS "Tables", round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "servatrice" ORDER BY (data_length + index_length) DESC;'
|
4
servatrice/scripts/maint_logs
Normal file
4
servatrice/scripts/maint_logs
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
#SCHEDULE WITH CRONTAB AND ADJUST THE INTERVALS FOR THE NUMBER OF DAYS OF LOGS TO KEEP IN THE DATABASE
|
||||
SQLCONFFILE="./mysql.cnf" #set this to the path that contains the mysql.cnf file
|
||||
mysql --defaults-file=$SQLCONFFILE -h localhost -e 'delete from servatrice.cockatrice_log where log_time < DATE_SUB(now(), INTERVAL 10 DAY)'
|
|
@ -1,3 +1,4 @@
|
|||
#!/bin/bash
|
||||
# SCHEDULE WITH CRONTAB BASED ON TIME PERIOD UNACTIVE ACCOUNT SHOULD BE REMOVED. UPDATE INTERVAL DATE TO BE NUMBER OF DAYS OLD (OR OLDER) TO REMOVE.
|
||||
mysql --defaults-file=./mysql.cnf -h localhost -e 'delete from servatrice.cockatrice_users where registrationDate < DATE_SUB(now(), INTERVAL 5 DAY) AND active = 0';
|
||||
SQLCONFFILE="./mysql.cnf" #set this to the path that contains the mysql.cnf file
|
||||
mysql --defaults-file=$SQLCONFFILE -h localhost -e 'delete from servatrice.cockatrice_users where registrationDate < DATE_SUB(now(), INTERVAL 5 DAY) AND active = 0';
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#!/bin/bash
|
||||
# SCHEDULE WITH CRONTAB BASED ON TIME PERIOD REPLAYS SHOULD BE SAVED UNTIL (EX: SCHEDULE ONCE A WEEK TO KEEP A WEEKS WORTH OF REPLAYS IN THE DB)
|
||||
mysql --defaults-file=./mysql.cnf -h localhost -e 'truncate table servatrice.cockatrice_replays;truncate table servatrice.cockatrice_replays_access'
|
||||
SQLCONFFILE="./mysql.cnf" #set this to the path that contains the mysql.cnf file
|
||||
mysql --defaults-file=$SQLCONFFILE -h localhost -e 'truncate table servatrice.cockatrice_replays;truncate table servatrice.cockatrice_replays_access'
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#!/bin/bash
|
||||
# SCHEDULE WITH CRONTAB TO RUN ONCE A MONTH
|
||||
mysql --defaults-file=./mysql.cnf -h localhost -e "delete from servatrice.cockatrice_sessions where start_time < DATE_SUB(now(), INTERVAL 1 MONTH)"
|
||||
SQLCONFFILE="./mysql.cnf" #set this to the path that contains the mysql.cnf file
|
||||
mysql --defaults-file=$SQLCONFFILE -h localhost -e "delete from servatrice.cockatrice_sessions where start_time < DATE_SUB(now(), INTERVAL 1 MONTH)"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#!/bin/bash
|
||||
# SCRIPT TO ADD THE FIRST ADMIN USER NAMED SERVATRICE WITH THE PASSWORD OF PASSWORD
|
||||
mysql --defaults-file=./mysql.cnf -h localhost -e "insert into servatrice.cockatrice_users (admin,name,password_sha512,active) values (1,'servatrice','jbB4kSWDmjaVzMNdU13n73SpdBCJTCJ/JYm5ZBZvfxlzbISbXir+e/aSvMz86KzOoaBfidxO0s6GVd8t00qC0TNPl+udHfECaF7MsA==',1);"
|
||||
SQLCONFFILE="./mysql.cnf" #set this to the path that contains the mysql.cnf file
|
||||
mysql --defaults-file=$SQLCONFFILE -h localhost -e "insert into servatrice.cockatrice_users (admin,name,password_sha512,active) values (1,'servatrice','jbB4kSWDmjaVzMNdU13n73SpdBCJTCJ/JYm5ZBZvfxlzbISbXir+e/aSvMz86KzOoaBfidxO0s6GVd8t00qC0TNPl+udHfECaF7MsA==',1);"
|
||||
|
|
Loading…
Reference in a new issue