Tool chain Backup

background

  • In fact, my backup awareness was not enough before, and I found that all the company’s tool chains were accessed from the external network of Aliyun, and what’s more terrible is that there is no scheduled backup (docker startup does not have persistence). Can’t imagine what will be the result of xx. After I arrived at the company, the first thing I did was to move to the Intranet. However, many people on the Intranet have accounts and the sudo permission is large, so backup is also necessary. After all, the Intranet is not safe.

  • Backup is necessary for basic operation and maintenance. It is also an important part of improving service availability. In case of disaster, backup can be used to restore services quickly. As an example, for example, gitLab mistakenly deleted data. Of course, GITLab has multiple backup mechanisms, and recovery is certain. Think about what a disaster it would have been if GitLab hadn’t backed up, and we’ve been warned by all sorts of things to back up, as long as the data is there.

The environment

  • Yapi confluence was, jira, gitlab, was started using docker
  • Gitlab, YAPI did persistence
  • Jira and Confluence are not persistent, so backup is required. If the container crashes, some data will be lost.

Important: The container does data persistence

Gitlab backup

Backup_gitlab. sh backup script #! /bin/bash backup_time=`date +"%Y-%m-%d"` docker exec -t gitlab-docker gitlab-rake gitlab:backup:create if [ $? -eq 0 ] then echo "gitlab ${backup_time} Successful backup" >> /root/backup.log else echo "gitlab ${backup_time} backup failed" >> /root/backup.log fi find /mnt/md0/gitlab-docker/data/backups/ -maxdepth 1 -mtime +7 -name "*.tar" | xargs rm -fCopy the code
Set a scheduled task. 30 1 * * * /root/backup_gitlab.sh >/dev/null 2>&1Copy the code

Jira backup

root@pc-Super-Server:~# cat backup_jira.sh #! /bin/bash backup_time= 'date +"%Y-%m-%d"' PGPASSWORD=jiradb pg_dump -h 172.168.1.235 -p 9999 -u jiradb > /mnt/md0/backup_data/jira/jiradb_${backup_time}.sql if [ $? -eq 0 ] then echo "jira ${backup_time} sql Successful backup" >> /root/backup.log else echo "jira ${backup_time} sql backup failed" >> /root/backup.log fi docker cp jira:/var/jira/data/ /mnt/md0/backup_data/jira/data/ docker cp jira:/var/jira/dbconfig.xml /mnt/md0/backup_data/jira/ Docker cp jira:/var/jira/caches/ / MNT /md0/backup_data/jira/ # Search for files that are 7 days old. Delete the files. Find/MNT /md0/backup_data/jira/ -maxdepth 1 -mtime +7 -name "*.sql" | xargs rm -fCopy the code
30 3 * * * /root/backup_jira.sh >/dev/null 2>&1

Copy the code

Confluence was backup

root@pc-Super-Server:~# cat backup_confluence.sh #! /bin/bash backup_time= 'date +"%Y-%m-%d"' PGPASSWORD=confdb pg_dump -h 172.168.1.235 -p 9999 -u confdb > /mnt/md0/backup_data/confluence/confdb_${backup_time}.sql if [ $? -eq 0 ] then echo "confluence ${backup_time} sql Successful backup" >> /root/backup.log else echo "confluence ${backup_time} sql backup failed" >> /root/backup.log fi docker cp confluence:/var/atlassian/confluence/attachments /mnt/md0/backup_data/confluence/ docker cp confluence:/var/atlassian/confluence/confluence.cfg.xml /mnt/md0/backup_data/confluence/ docker cp Confluence was: / var/atlassian confluence was/index/MNT/md0 / backup_data/confluence was / # search the files to delete the find seven days ago /mnt/md0/backup_data/confluence/ -maxdepth 1 -mtime +7 -name "*.sql" | xargs rm -fCopy the code
0  3 * * * /root/backup_confluence.sh >/dev/null 2>&1

Copy the code

Yapi backup

root@pc-Super-Server:~# cat backup_yapi.sh Backup script #! /bin/bash backup_time=`date +"%Y-%m-%d"` docker exec -t mongo-yapi mongodump -u yapi -p yapi2019 -d yapi -o /data/db/backups/`date +'%Y-%m-%d'`/ if [ $? -eq 0 ] then echo "yapi ${backup_time} Successful backup" >> /root/backup.log else echo "yapi ${backup_time} backup failed" >> /root/backup.log fi find /data/yapi-data/backups/ -maxdepth 1 -type d -mtime +7 |xargs rm -rfCopy the code
Crontab scheduled task 30 2 * * * /root/backup_yapi.sh >/dev/null 2>&1Copy the code

Yapi recovery

  • Docker launches a brand new YAPI and Mongo
mongo use admin db.createUser( { user: "admin", pwd: "admin", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } ) db.createUser( { user: "yapi", pwd: "yapi2019", roles: [ { role: "dbAdmin", db: "yapi" } ] } ) exit mongorestore -u yapi -p yapi2019 -d yapi --authenticationDatabase admin --drop --dir /root/yapi/ /root/yapi is the backup data directoryCopy the code

Note: After all backup script tests are completed, restore a test environment using backup data to verify backup data coverage