2 # ============LICENSE_START=======================================================
4 # ================================================================================
5 # Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 # ================================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END=========================================================
23 #########################################################################
27 #########################################################################
30 echo -n "syntax: $(basename $0) "
32 echo -n "[--backup <backup-dir-location>] | "
33 echo -n "[--restore <backup-dir-location>])"
37 if [[ $DEBUG == y ]]; then
38 echo "-- ${FUNCNAME[0]} $@ --"
42 if [[ -z ${POLICY_HOME} ]]; then
43 echo "error: ${POLICY_HOME} is not set"
48 if [[ -z ${BACKUP_DIR} ]]; then
49 echo "error: a backup directory must be provided"
54 /bin/mkdir -p ${BACKUP_DIR} > /dev/null 2>&1
55 if [[ ! -d ${BACKUP_DIR} ]]; then
56 echo "error: ${BACKUP_DIR} is not a directory"
60 if [[ ! -w ${BACKUP_DIR} ]] ; then
61 echo "error: ${BACKUP_DIR} is not writable"
65 if [ "$(ls -A ${BACKUP_DIR})" ]; then
66 echo "error: ${BACKUP_DIR} must be empty"
70 echo "backing up ${POLICY_HOME} to ${BACKUP_DIR} to.."
75 --exclude servers/pap/webapps/pap \
76 --exclude servers/pdp/webapps/pdp \
77 --exclude servers/pypdp/webapps/PyPDPServer \
78 --exclude servers/console/webapps/policy \
84 if [[ $DEBUG == y ]]; then
85 echo "-- ${FUNCNAME[0]} $@ --"
89 if [[ -z ${POLICY_HOME} ]]; then
90 echo "error: ${POLICY_HOME} is not set"
95 if [[ -z ${BACKUP_DIR} ]]; then
96 echo "error: a backup directory must be provided"
101 if [[ ! -d ${BACKUP_DIR} ]]; then
102 echo "error: ${BACKUP_DIR} is not a directory"
106 if [ "$(ls -A ${BACKUP_DIR})" ]; then
107 echo "OK: ${BACKUP_DIR} has content"
109 echo "error: ${BACKUP_DIR} is empty"
113 echo "restoring from ${BACKUP_DIR} to ${POLICY_HOME} .."
114 rsync -a ${BACKUP_DIR}/* ${POLICY_HOME}
120 # command line options parsing
121 until [[ -z "$1" ]]; do
126 -b|--backup) OPERATION=backup
130 -r|--restore) OPERATION=restore
141 # operation validation
145 restore) restore $DIR
147 *) echo "invalid operation (${OPERATION}): must be in {backup|restore}";