Last active
June 12, 2018 06:59
-
-
Save jailbirt/4e6d9cc3e58bb2a95429 to your computer and use it in GitHub Desktop.
backup and restore geonode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
option=$1 | |
geonodeBackup='/home/geonode_backups' | |
mkdir $geonodeBackup | |
date=$(date +%Y-%m-%d-%H) | |
function stopServices | |
{ | |
echo "Stopping services" | |
sudo service apache2 stop | |
sudo service tomcat7 stop | |
sudo service postgresql stop | |
} | |
function startServices | |
{ | |
echo "Restarting services" | |
sudo service apache2 start | |
sudo service tomcat7 start | |
sudo service postgresql start | |
} | |
case $option in | |
backup) | |
echo "Sql dump" | |
sudo -u postgres -i pg_dump -c -Fc geonode > $geonodeBackup/geonodedb.backup | |
sudo -u postgres -i pg_dump -c -Fc geonodegisdb93 > $geonodeBackup/geonodegisdb93.backup | |
stopServices | |
echo "Making Files/Directory backup" | |
cd $geonodeBackup # go into the folder for backup | |
tar -cvzf geonodeConfigBackup.tgz /etc/geonode | |
tar -zcvf geonodeVarDataBackup.tgz /var/lib/geoserver/geonode-data/ | |
tar -zcvf geonodeUsrDataBackup.tgz /usr/share/geoserver/data/ | |
tar -zcvf geonodeWWWDataBackup.tgz /var/www/geonode/ | |
tar -cvzf geonodei18nBackup.tgz /usr/local/lib/python2.7/dist-packages/geonode/locale/ | |
tar -cvzf geonodePyDjangoBackup.tgz /usr/local/lib/python2.7/dist-packages/geonode/ | |
tar -cvzf geonodePyDjangoEggBackup.tgz /usr/local/lib/python2.7/dist-packages/GeoNode-2.0-py2.7.egg-info/ | |
startServices | |
Message="backup finished" | |
;; | |
restore) | |
stopServices | |
cd $geonodeBackup | |
for i in $(ls *.tgz) | |
do | |
echo "Restoring: $i" | |
sudo tar -C / -xvzf $i | |
done | |
startServices | |
sudo -u postgres dropdb geonode; | |
sudo -u postgres createdb geonode; | |
sudo -u postgres -i pg_restore -Fc -d geonode $geonodeBackup/geonodedb.backup | |
Message="restore finished" | |
;; | |
*) | |
Message="please use: $0 (backup|restore)" | |
;; | |
esac | |
echo $Message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment