SHARE
TWEET

Untitled

a guest Jun 15th, 2017 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. NOW=$(date +"%d-%m-%Y-%H-%M-%S")
  3. SQL_DUMP_FILE="backupProd.$NOW.sql"
  4. SQL_PREPROD_FILE="preprod.sql"
  5. NEW_BACKUP_FILE="lastMondayBackup.tar.gz"
  6. OLD_BACKUP_FILE="previousMondayBackup.tar.gz"
  7. SQL_USER="root"
  8. SQL_PASSWORD="root"
  9. SQL_PROD_TABLE_NAME="prod"
  10. SQL_PREPROD_TABLE_NAME="preprod"
  11. ANALYTICS_PROD_ACOUNT=""
  12. ANALYTICS_PREPROD_ACOUNT=""
  13. GSUB_REPLACE_STRING="gsub(\"www.mywebsite.fr\",\"preprod.mywebsite.fr\");"
  14. BACKUP_PATH="/root/backups/"
  15.  
  16. echo "STEP #1 // BACKUP"
  17.  
  18. echo "- Dumping DB to create $BACKUP_PATH$SQL_DUMP_FILE file, please wait..."
  19. mysqldump -u $SQL_USER -p$SQL_PASSWORD $SQL_PROD_TABLE_NAME>$BACKUP_PATH$SQL_DUMP_FILE
  20. chmod 755 $BACKUP_PATH$SQL_DUMP_FILE
  21.  
  22. echo "Move up previous backup ($NEW_BACKUP_FILE to $OLD_BACKUP_FILE)"
  23. cp $BACKUP_PATH$NEW_BACKUP_FILE $BACKUP_PATH$OLD_BACKUP_FILE
  24.  
  25. echo "- Zipping current dump $BACKUP_PATH$SQL_DUMP_FILE to $BACKUP_PATH$NEW_BACKUP_FILE"
  26. gzip -fc -9 $BACKUP_PATH$SQL_DUMP_FILE > $BACKUP_PATH$NEW_BACKUP_FILE
  27.  
  28. echo "STEP #2 // UPDATE PREPROD"
  29.  
  30. echo "- replace prod urls by preprod ones"
  31. echo "$BACKUP_PATH$SQL_DUMP_FILE > $BACKUP_PATH$SQL_PREPROD_FILE"
  32. awk '{$GSUB_REPLACE_STRINGprint}' $BACKUP_PATH$SQL_DUMP_FILE > $BACKUP_PATH$SQL_PREPROD_FILE
  33.  
  34. echo "- import all tables to preprod db"
  35. mysql -u $SQL_USER -p$SQL_PASSWORD $SQL_PREPROD_TABLE_NAME < $BACKUP_PATH$SQL_PREPROD_FILE
  36.  
  37. echo "-sql safe updates off"
  38. mysql -u $SQL_USER -p$SQL_PASSWORD -e 'SET SQL_SAFE_UPDATES = 0;'
  39.  
  40. #echo "-use google Analytics preprod Account"
  41. #mysql -u $SQL_USER -p$SQL_PASSWORD $SQL_PREPROD_TABLE_NAME -e 'UPDATE core_config_data SET value="" WHERE path = "google/analytics/account" AND scope_id = "1";'
  42.  
  43. echo "-sql safe updates on"
  44. mysql -u $SQL_USER -p$SQL_PASSWORD -e 'SET SQL_SAFE_UPDATES = 1;'
  45.  
  46. echo "STEP #3 // CLEAN UP"
  47.  
  48. echo "- remove $BACKUP_PATH$SQL_DUMP_FILE"
  49. rm $BACKUP_PATH$SQL_DUMP_FILE
  50.  
  51. echo "- remove $BACKUP_PATH$SQL_PREPROD_FILE"
  52. rm $BACKUP_PATH$SQL_PREPROD_FILE
  53.  
  54. echo "all done :)"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top