Guest User

Untitled

a guest
Jan 12th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #This script will backup our wiki instances, into /var/backup
  4.  
  5. if [ -e "/var/backup/LOCKED" ]
  6. then
  7. echo "ERROR - THE BACKUPS ARE LOCKED"
  8. echo "CHECK THAT THIS SCRIPT IS NOT RUNNING"
  9. echo "ELSE RELEASE THE LOCK MANUALLY"
  10. exit 1
  11. fi
  12.  
  13. #Lock the backups
  14. touch /var/backup/LOCKED
  15.  
  16. cd /var/www
  17. for i in `ls -1`;
  18. do
  19. #Check we actually have a wiki that exists
  20. if [ -e "/var/www/${i}/LocalSettings.php" ]
  21. then
  22. echo ${i}
  23. #we have a wiki - back it up.
  24. #Backup the DB
  25. # Get the username and password out of the LocalSettings
  26. export username=`cat /var/www/${i}/LocalSettings.php | grep wgDBuser | awk '{ print $3 }' | sed -e 's/;//' | sed -e 's/\"//g'`
  27. export password=`cat /var/www/${i}/LocalSettings.php | grep wgDBpassword | awk '{ print $3 }' | sed -e 's/;//' | sed -e 's/\"//g'`
  28. export database=`cat /var/www/${i}/LocalSettings.php | grep wgDBname | awk '{ print $3 }' | sed -e 's/;//' | sed -e 's/\"//g'`
  29. #Now we can dump the DB and other items we need. Move last nights backup aside
  30. mv /var/backup/wiki_${i}.sql /var/backup/wiki_${i}.sql.old
  31. mysqldump --add-drop-table ${database} --user=${username} --password=${password} > /var/backup/wiki_${i}.sql
  32. #Now backup the images dir and configs
  33. cd /var/www/${i}
  34. #This avoids a nasty error
  35. touch ./Extensions.php
  36. tar -czf /var/backup/wiki_${i}_images.tar.gz ./images ./LocalSettings.php ./Extensions.php
  37. cd /var/www
  38. fi
  39. #back to where we started
  40. done
  41.  
  42. #Finally, since extensions are shared, back them up also
  43. cd /usr/share/mediawiki
  44. tar -czf /var/backup/wiki_extensions.tar.gz ./extensions
  45.  
  46. #We are done, so sync and release the lock
  47. sync
  48. rm /var/backup/LOCKED
Add Comment
Please, Sign In to add comment