support for container backup
PROD-21837
Change-Id: Id6d475fd27488998c6ba81d038036e95b8f6787e
diff --git a/README.rst b/README.rst
index 6c47157..c6b2af8 100644
--- a/README.rst
+++ b/README.rst
@@ -35,6 +35,22 @@
More options to relocate local backups can be done using salt-formula-backupninja.
+Backup client container with ssh/rsync remote host
+
+.. code-block:: yaml
+
+ cassandra:
+ backup:
+ client:
+ enabled: true
+ full_backups_to_keep: 3
+ hours_before_full: 24
+ containers:
+ - opencontrail_controller_1
+ target:
+ host: cfg01
+ home_dir: server-home-dir
+
Backup client with local backup only
.. code-block:: yaml
@@ -184,6 +200,23 @@
.. note:: restore_latest param with a value of 1 means to restore db from the last full backup. 2 would mean to restore second latest full backup.
+Client restore container from remote backup:
+
+.. code-block:: yaml
+
+ cassandra:
+ backup:
+ client:
+ enabled: true
+ full_backups_to_keep: 3
+ hours_before_full: 24
+ containers:
+ - opencontrail_controller_1
+ target:
+ host: cfg01
+ restore_latest: 1
+ restore_from: remote
+
Read more
=========
diff --git a/cassandra/files/backup/cassandra-backup-client-restore-call.sh b/cassandra/files/backup/cassandra-backup-client-restore-call.sh
index 3dbc109..9a33acd 100644
--- a/cassandra/files/backup/cassandra-backup-client-restore-call.sh
+++ b/cassandra/files/backup/cassandra-backup-client-restore-call.sh
@@ -66,18 +66,64 @@
fi
echo "Restoring db from $FULLBACKUPDIR/$FULL/"
+{%- if backup.client.containers is defined %}
+{%- for container_name in backup.client.containers %}
+
+docker exec {{ container_name }} mkdir -p $FULLBACKUPDIR/$FULL/
+docker cp $SCRIPTDIR/cassandra-backup-restore.sh {{ container_name }}:/
+
+for filename in $FULLBACKUPDIR/$FULL/*; do docker cp $filename {{ container_name }}:$filename; docker exec {{ container_name }} /cassandra-backup-restore.sh -f $filename; docker exec {{ container_name }} rm -rf $filename; done
+
+{%- endfor %}
+
+{%- else %}
+
for filename in $FULLBACKUPDIR/$FULL/*; do $SCRIPTDIR/cassandra-backup-restore.sh -f $filename; done
+{%- endif %}
+
{%- else %}
FULL=`find $BACKUPDIR -mindepth 1 -maxdepth 1 -type d -printf "%P\n" | sort -nr | head -{{ backup.client.restore_latest }} | tail -1`
echo "Restoring db from $BACKUPDIR/$FULL/"
+
+{%- if backup.client.containers is defined %}
+{%- for container_name in backup.client.containers %}
+
+docker exec {{ container_name }} mkdir -p $BACKUPDIR/$FULL/
+docker cp $SCRIPTDIR/cassandra-backup-restore.sh {{ container_name }}:/
+
+for filename in $BACKUPDIR/$FULL/*; do docker cp $filename {{ container_name }}:$filename; docker exec {{ container_name }} /cassandra-backup-restore.sh -f $filename; docker exec {{ container_name }} rm -rf $filename; done
+
+{%- endfor %}
+
+{%- else %}
+
for filename in $BACKUPDIR/$FULL/*; do $SCRIPTDIR/cassandra-backup-restore.sh -f $filename; done
{%- endif %}
+{%- endif %}
+
+{%- if backup.client.containers is defined %}
+{%- for container_name in backup.client.containers %}
+
+docker exec {{ container_name }} nodetool repair
+RC=$?
+if [ $RC -eq 0 ]; then
+ touch $DBALREADYRESTORED
+fi
+
+{%- endfor %}
+
+{%- else %}
+
nodetool repair
RC=$?
if [ $RC -eq 0 ]; then
touch $DBALREADYRESTORED
fi
+
+{%- endif %}
+
+
diff --git a/cassandra/files/backup/cassandra-backup-client-runner-call.sh b/cassandra/files/backup/cassandra-backup-client-runner-call.sh
index 3ce2b5f..c87b1e4 100644
--- a/cassandra/files/backup/cassandra-backup-client-runner-call.sh
+++ b/cassandra/files/backup/cassandra-backup-client-runner-call.sh
@@ -54,7 +54,7 @@
function check_dependencies() {
# Function to iterate through a list of required executables to ensure
# they are installed and executable by the current user.
- DEPS="awk basename cp cqlsh date dirname echo find "
+ DEPS="awk basename cp date dirname echo find "
DEPS+="getopt grep hostname mkdir rm sed tail tar "
for bin in $DEPS; do
$( which $bin >/dev/null 2>&1 ) || NOTFOUND+="$bin "
@@ -91,10 +91,28 @@
TIMESTAMP=$( date +"%Y%m%d%H%M%S" )
DATESTRING=$( date )
+ {%- if backup.client.containers is defined %}
+ {%- for container_name in backup.client.containers %}
+
+ docker exec {{ container_name }} cqlsh $CASIP -e "DESC KEYSPACES" |perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | sed '/^$/d' > Keyspace_name_schema.cql
+ #docker exec {{ container_name }} cqlsh 172.16.10.96 -e "DESC KEYSPACES" |perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | sed '/^$/d' > Keyspace_name_schema.cql
+ sed 's/\"//g' Keyspace_name_schema.cql > KEYSPACES_LIST
+ docker cp $SCRIPTDIR/cassandra-backup-runner.sh {{ container_name }}:/
+ for i in `cat KEYSPACES_LIST`; do docker exec {{ container_name }} /cassandra-backup-runner.sh -k $i -t $TIMESTAMP -d $DATESTRING; done
+ docker cp {{ container_name }}:/$BACKUPDIR/$TIMESTAMP $BACKUPDIR
+ docker exec {{ container_name }} rm -rf $BACKUPDIR/$TIMESTAMP
+
+ {%- endfor %}
+
+ {%- else %}
+
cqlsh $CASIP -e "DESC KEYSPACES" |perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | sed '/^$/d' > Keyspace_name_schema.cql
sed 's/\"//g' Keyspace_name_schema.cql > KEYSPACES_LIST
+ docker cp /usr/local/bin/cassandra-backup-runner.sh {{ container_name }}:/
for i in `cat KEYSPACES_LIST`; do $SCRIPTDIR/cassandra-backup-runner.sh -k $i -t $TIMESTAMP -d $DATESTRING; done
+ {%- endif %}
+
# rsync just the new or modified backup files
# ---------