blob: c63c8777e2e3f03c45d127151507c3be702b207e [file] [log] [blame]
Sergey Galkin24ebd762020-01-14 14:36:34 +04001#!/bin/bash -ex
2set -e
3cd "$(dirname "$0")"
4DATE=$(date +%F)
5SHOST=sre-ci.scc.mirantis.net
6SSH_CMD="ssh $SHOST"
7BACKUP_MAIN_DIR="${HOME}/sre/jenkins-backup"
8BACKUP_MAIN_REMOTE_DIR="/home/$USER/jenkins"
9echo "Prepare for backup"
10$SSH_CMD sudo rm -rf ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE
11$SSH_CMD rm -f ${BACKUP_MAIN_REMOTE_DIR}/${DATE}.tar.gz
12$SSH_CMD mkdir -p ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE
13scp ./jenkins-rsync.includes $SHOST:${BACKUP_MAIN_REMOTE_DIR}/jenkins-rsync.includes
14$SSH_CMD sudo rsync -avz --include-from=${BACKUP_MAIN_REMOTE_DIR}/jenkins-rsync.includes --exclude=\'*\' /var/jenkins_home/ ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE/
15$SSH_CMD sudo chown -R sgalkin:sgalkin ${BACKUP_MAIN_REMOTE_DIR}/backups
16$SSH_CMD tar czvf ${BACKUP_MAIN_REMOTE_DIR}/backups/${DATE}.tar.gz ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE
17$SSH_CMD rm -rf ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE
18mkdir -p ${BACKUP_MAIN_DIR}/backups
19scp $SHOST:${BACKUP_MAIN_REMOTE_DIR}/backups/${DATE}.tar.gz ${BACKUP_MAIN_DIR}/backups/