Sergey Galkin | 24ebd76 | 2020-01-14 14:36:34 +0400 | [diff] [blame] | 1 | #!/bin/bash -ex |
| 2 | set -e |
| 3 | cd "$(dirname "$0")" |
| 4 | DATE=$(date +%F) |
| 5 | SHOST=sre-ci.scc.mirantis.net |
| 6 | SSH_CMD="ssh $SHOST" |
| 7 | BACKUP_MAIN_DIR="${HOME}/sre/jenkins-backup" |
| 8 | BACKUP_MAIN_REMOTE_DIR="/home/$USER/jenkins" |
| 9 | echo "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 |
| 13 | scp ./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 |
| 18 | mkdir -p ${BACKUP_MAIN_DIR}/backups |
| 19 | scp $SHOST:${BACKUP_MAIN_REMOTE_DIR}/backups/${DATE}.tar.gz ${BACKUP_MAIN_DIR}/backups/ |