Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- dbase=(
- accounts
- accounts_banned
- auction_house
- chars
- char_blacklist
- char_effects
- char_equip
- char_exp
- char_inventory
- char_jobs
- char_look
- char_merit
- char_pet
- char_pet_name
- char_points
- char_profile
- char_recast
- char_skills
- char_spells
- char_stats
- char_storage
- char_style
- char_vars
- char_weapon_skill_points
- delivery_box
- linkshells
- server_variables
- zone_settings
- )
- FILE=dsbackup.sql.`date +"%Y%m%d"`
- DBSERVER=127.0.0.1
- DATABASE=dspdb
- USER=darkstar
- PASS=55655
- backdb () {
- # (2) in case you run this more than once a day, remove the previous version of the file
- unalias rm 2> /dev/null
- rm ${FILE} 2> /dev/null
- rm ${FILE}.gz 2> /dev/null
- # (3) make files if not made
- echo "Starting Backup"
- mkdir backup
- for i in "${dbase[@]}"
- do
- :
- touch backup/$i.sql
- mysqldump --opt --user=${USER} --password=${PASS} ${DATABASE} $i > backup/$i.sql
- done
- echo "Backup of DATABASE done"
- # (5) tar the mysql database dump
- echo "Starting to Compress Files"
- tar zcvf backup.`date +"%Y%m%d"`.tar.gz backup/
- echo "Compression done"
- # (6) delete folder
- clear
- rm -rf backup
- # (7) show the result
- ls -l backup.`date +"%Y%m%d"`.tar.gz
- }
- restdb () {
- # (2) Decompress the file
- echo "Starting Decompression"
- fn=$(ls -t backup.*.tar.gz | head -1)
- tar -xzf $fn
- echo "Decompression of $fn Done"
- # (3) Import The tables
- echo "Starting to Import Tables"
- for i in "${dbase[@]}"
- do
- :
- mysql --user=${USER} --password=${PASS} ${DATABASE} < backup/$i.sql
- done
- # (5) show the user the result
- echo "Script done Tables Imported"
- }
- # Cases
- case "$1" in
- -backup )
- backdb
- ;;
- -restore )
- restdb
- ;;
- "" )
- echo "Usage -backup | -restore"
- ;;
- *)
- exit 1
- ;;
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement