Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #This script will backup our wiki instances, into /var/backup
- if [ -e "/var/backup/LOCKED" ]
- then
- echo "ERROR - THE BACKUPS ARE LOCKED"
- echo "CHECK THAT THIS SCRIPT IS NOT RUNNING"
- echo "ELSE RELEASE THE LOCK MANUALLY"
- exit 1
- fi
- #Lock the backups
- touch /var/backup/LOCKED
- cd /var/www
- for i in `ls -1`;
- do
- #Check we actually have a wiki that exists
- if [ -e "/var/www/${i}/LocalSettings.php" ]
- then
- echo ${i}
- #we have a wiki - back it up.
- #Backup the DB
- # Get the username and password out of the LocalSettings
- export username=`cat /var/www/${i}/LocalSettings.php | grep wgDBuser | awk '{ print $3 }' | sed -e 's/;//' | sed -e 's/\"//g'`
- export password=`cat /var/www/${i}/LocalSettings.php | grep wgDBpassword | awk '{ print $3 }' | sed -e 's/;//' | sed -e 's/\"//g'`
- export database=`cat /var/www/${i}/LocalSettings.php | grep wgDBname | awk '{ print $3 }' | sed -e 's/;//' | sed -e 's/\"//g'`
- #Now we can dump the DB and other items we need. Move last nights backup aside
- mv /var/backup/wiki_${i}.sql /var/backup/wiki_${i}.sql.old
- mysqldump --add-drop-table ${database} --user=${username} --password=${password} > /var/backup/wiki_${i}.sql
- #Now backup the images dir and configs
- cd /var/www/${i}
- #This avoids a nasty error
- touch ./Extensions.php
- tar -czf /var/backup/wiki_${i}_images.tar.gz ./images ./LocalSettings.php ./Extensions.php
- cd /var/www
- fi
- #back to where we started
- done
- #Finally, since extensions are shared, back them up also
- cd /usr/share/mediawiki
- tar -czf /var/backup/wiki_extensions.tar.gz ./extensions
- #We are done, so sync and release the lock
- sync
- rm /var/backup/LOCKED
Add Comment
Please, Sign In to add comment