备份gitlab代码仓库脚本

1.脚本能做什么

       将gitlab代码仓库备份并将备份迁移到指定服务器,此时我将代码仓库上传到了minio的某个bucket下,便于查看情况,本次脚本并没有做定时执行的脚本,所以脚本需要手动执行。

      文中涉及的配置服务器之间免密,以及授予脚本可执行权限这些一概不讲,太基础不会的自己百度。

2.脚本内容

      我的gitlab在docker容器里面,而映射的数据路径是/home/gitlab/data下,如果你的gitlab是原生方式安装,请以实际路径为准,一般在/var/opt/gitlab/backups下,备份思路是一样的。

     代码服务器与minio服务器做了免密登录,其实只要执行完脚本备份就可以了。没有minio手动拷贝到硬盘也是不错的选择。

#! /bin/bash
echo "开始删除映射backup目录下的文件"
cd /home/gitlab/data/backups/ && rm -rf ./*.tar
echo "delete done,开始执行备份"
docker exec gitlab gitlab-rake gitlab:backup:create
echo "生成的备份文件在------>>>>>>>>>/home/gitlab/data/backups"
cd /home/gitlab/data/backups
scp *.tar [email protected]:/home/minio/data/gitlab/

3.查看脚本执行情况

[root@localhost ~]# sh backup_gitlab.sh 
开始删除映射backup目录下的文件
delete done,开始执行备份
2023-03-14 07:21:49 +0000 -- Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2023-03-14 07:21:50 +0000 -- done
2023-03-14 07:21:50 +0000 -- Dumping repositories ...
 * gitlab-instance-56925b38/Monitoring (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ... 

2023-03-14 07:21:56 +0000 -- done
2023-03-14 07:21:56 +0000 -- Dumping uploads ... 
2023-03-14 07:21:57 +0000 -- done
2023-03-14 07:21:57 +0000 -- Dumping builds ... 
2023-03-14 07:21:57 +0000 -- done
2023-03-14 07:21:57 +0000 -- Dumping artifacts ... 
2023-03-14 07:21:57 +0000 -- done
2023-03-14 07:21:57 +0000 -- Dumping pages ... 
2023-03-14 07:21:57 +0000 -- done
2023-03-14 07:21:57 +0000 -- Dumping lfs objects ... 
2023-03-14 07:21:57 +0000 -- done
2023-03-14 07:21:57 +0000 -- Dumping container registry images ... 
2023-03-14 07:21:57 +0000 -- [DISABLED]
Creating backup archive: 1678778517_2023_03_14_13.12.3_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data 
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.
生成的备份文件在------>>>>>>>>>/home/gitlab/data/backups
1678778517_2023_03_14_13.12.3_gitlab_backup.tar 

 minio看下,扔过去了

备份gitlab代码仓库脚本_第1张图片

你可能感兴趣的:(gitlab,docker,容器)