Skip to content

Instantly share code, notes, and snippets.

@jondoig
Forked from jailbirt/backupRestoreGeonode.sh
Created June 12, 2018 06:59
Show Gist options
  • Save jondoig/23fa1de26db0ee359d3a03741319fbfa to your computer and use it in GitHub Desktop.
Save jondoig/23fa1de26db0ee359d3a03741319fbfa to your computer and use it in GitHub Desktop.
backup and restore geonode
#!/bin/bash
option=$1
geonodeBackup=' /mnt/data/citydata_backup'
sudo mkdir -p $geonodeBackup
sudo chown -R $USER $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 postgresql start
sudo service tomcat7 start
sudo service apache2 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 geonode_data > $geonodeBackup/geonode_data_db.backup
stopServices
echo "Making Files/Directory backup"
cd $geonodeBackup # go into the folder for backup
# Change geonode folder location
# tar -cvzf geonodeConfigBackup.tgz /etc/geonode
tar -cvzf geonodeConfigBackup.tgz /mnt/data/geonode/geonode
# Not needed in Geonode 2.4? Relic of Geonode 2.0?
# tar -zcvf geonodeVarDataBackup.tgz /var/lib/geoserver/geonode-data/ # ToDo: change folder location
# Change geoserver data folder location
# tar -zcvf geonodeUsrDataBackup.tgz /usr/share/geoserver/data/
tar -zcvf geonodeUsrDataBackup.tgz /mnt/data/geoserver_data
# Not needed in Geonode 2.4? Relic of Geonode 2.0?
# tar -zcvf geonodeWWWDataBackup.tgz /var/www/geonode/ # ToDo: change folder location
# Try skipping these - why are they needed?
# tar -cvzf geonodei18nBackup.tgz /usr/local/lib/python2.7/dist-packages/geonode/locale/ # OK: folder exists on CityData
# Try skipping these - why are they needed?
# tar -cvzf geonodePyDjangoBackup.tgz /usr/local/lib/python2.7/dist-packages/geonode/ # OK: folder exists on CityData
# change folder location for CityData
# -cvzf geonodePyDjangoEggBackup.tgz /usr/local/lib/python2.7/dist-packages/GeoNode-2.0-py2.7.egg-info/
# tar -cvzf geonodePyDjangoEggBackup.tgz /usr/local/lib/python2.7/dist-packages/GeoNode-2.4.dev20170525043502.egg-info
# Try skipping these - why are they needed?
# tar -cvzf geonodePyDjangoEggBackup.tgz /usr/local/lib/python2.7/dist-packages/GeoNode-2.4.dev*.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
sudo -u postgres -i pg_restore -Fc -d geonode_data $geonodeBackup/geonode_data_db.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