blob: c63c8777e2e3f03c45d127151507c3be702b207e [file] [log] [blame]
#!/bin/bash -ex
set -e
cd "$(dirname "$0")"
DATE=$(date +%F)
SHOST=sre-ci.scc.mirantis.net
SSH_CMD="ssh $SHOST"
BACKUP_MAIN_DIR="${HOME}/sre/jenkins-backup"
BACKUP_MAIN_REMOTE_DIR="/home/$USER/jenkins"
echo "Prepare for backup"
$SSH_CMD sudo rm -rf ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE
$SSH_CMD rm -f ${BACKUP_MAIN_REMOTE_DIR}/${DATE}.tar.gz
$SSH_CMD mkdir -p ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE
scp ./jenkins-rsync.includes $SHOST:${BACKUP_MAIN_REMOTE_DIR}/jenkins-rsync.includes
$SSH_CMD sudo rsync -avz --include-from=${BACKUP_MAIN_REMOTE_DIR}/jenkins-rsync.includes --exclude=\'*\' /var/jenkins_home/ ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE/
$SSH_CMD sudo chown -R sgalkin:sgalkin ${BACKUP_MAIN_REMOTE_DIR}/backups
$SSH_CMD tar czvf ${BACKUP_MAIN_REMOTE_DIR}/backups/${DATE}.tar.gz ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE
$SSH_CMD rm -rf ${BACKUP_MAIN_REMOTE_DIR}/backups/$DATE
mkdir -p ${BACKUP_MAIN_DIR}/backups
scp $SHOST:${BACKUP_MAIN_REMOTE_DIR}/backups/${DATE}.tar.gz ${BACKUP_MAIN_DIR}/backups/