Thomas Vachuska | 58bf491 | 2017-10-31 12:00:32 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # ONOS utility to produce a backup archive of all persistent data. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)} |
| 7 | ONOS_DEFAULT_ARCHIVE=$(dirname $ONOS_HOME)/onos-data.tar.gz |
Thomas Vachuska | 3770b08 | 2019-01-02 16:38:37 -0800 | [diff] [blame] | 8 | ONOS_KARAF=$ONOS_HOME/apache-karaf-4.2.2 |
Thomas Vachuska | 58bf491 | 2017-10-31 12:00:32 -0700 | [diff] [blame] | 9 | |
| 10 | # Fetch the name of the archive or use a default if none is specified |
| 11 | archive=${1:-$ONOS_DEFAULT_ARCHIVE} |
| 12 | archive=$(cd "$(dirname "$archive")"; pwd)/$(basename "$archive") |
| 13 | |
| 14 | # Make sure that the apache karaf data directory exists |
| 15 | [ ! -d $ONOS_KARAF/data ] && echo "ONOS data directory not found" && exit 1 |
| 16 | |
| 17 | # Make sure that the archive lies outside of $ONOS_HOME for safety |
| 18 | [[ "$archive" =~ ^$ONOS_HOME/.* ]] && \ |
| 19 | echo "Archive cannot be in $ONOS_HOME directory tree" && exit 1 |
| 20 | |
| 21 | # Make sure that the archive file does not already exist |
| 22 | [ -f $archive ] && echo "Archive $archive already exists" && exit 1 |
| 23 | |
| 24 | # Make sure we can write the archive |
| 25 | ! touch $archive 2>/dev/null && \ |
| 26 | echo "No permission to write archive $archive" && exit 1 |
| 27 | rm -f $archive |
| 28 | |
| 29 | # Now produce the archive using the subset of the data directory tree |
| 30 | cd $ONOS_KARAF |
| 31 | tar zcf $archive data/db data/log |