【git學習】在CenterOS系統上恢復GitLab時出現錯誤:tar: 由於前次錯誤,將以上次的錯誤狀態退出 unpacking backup failed
阿新 • • 發佈:2018-12-17
一、問題描述
今天在測試加密GitLab備份檔案之後,進行解密,然後再恢復GitLab的時候,恢復失敗,報瞭如下的錯誤:
tar: db:無法 mkdir: 許可權不夠
tar: db:無法 mkdir: 許可權不夠
tar: db/database.sql.gz:無法 open: 沒有那個檔案或目錄
tar: uploads.tar.gz:無法 open: 許可權不夠
tar: builds.tar.gz:無法 open: 許可權不夠
tar: artifacts.tar.gz:無法 open: 許可權不夠
tar: pages.tar.gz:無法 open: 許可權不夠
tar: lfs.tar.gz:無法 open: 許可權不夠
tar: backup_information.yml:無法 open: 許可權不夠
tar: 由於前次錯誤,將以上次的錯誤狀態退出
unpacking backup failed
詳細錯誤如下:
tar: repositories:無法 mkdir: 許可權不夠 tar: repositories/caokuishun:無法 mkdir: 沒有那個檔案或目錄 tar: repositories:無法 mkdir: 許可權不夠 tar: repositories/caokuishun/EKOCelluarViewMod.bundle:無法 open: 沒有那個檔案或目錄 tar: repositories:無法 mkdir: 許可權不夠 tar: repositories/caokuishun/SDKTest.bundle:無法 open: 沒有那個檔案或目錄 tar: repositories:無法 mkdir: 許可權不夠 tar: repositories/ReactNative:無法 mkdir: 沒有那個檔案或目錄 tar: repositories:無法 mkdir: 許可權不夠 tar: repositories/ReactNative/Binding.bundle:無法 open: 沒有那個檔案或目錄 tar: db:無法 mkdir: 許可權不夠 tar: db:無法 mkdir: 許可權不夠 tar: db/database.sql.gz:無法 open: 沒有那個檔案或目錄 tar: uploads.tar.gz:無法 open: 許可權不夠 tar: builds.tar.gz:無法 open: 許可權不夠 tar: artifacts.tar.gz:無法 open: 許可權不夠 tar: pages.tar.gz:無法 open: 許可權不夠 tar: lfs.tar.gz:無法 open: 許可權不夠 tar: backup_information.yml:無法 open: 許可權不夠 tar: 由於前次錯誤,將以上次的錯誤狀態退出 unpacking backup failed [
[email protected] backups]# cd ../ [[email protected] gitlab]# ll 總用量 16 drwxr-xr-x. 2 root root 58 10月 23 16:25 backups -rw-------. 1 root root 38 10月 20 18:07 bootstrapped drwx------. 2 git root 44 10月 23 16:00 gitaly drwx------. 3 git root 25 10月 23 16:47 git-data drwxr-xr-x. 3 git root 19 10月 20 17:18 gitlab-ci drwxr-xr-x. 2 git root 31 10月 20 18:08 gitlab-monitor drwxr-xr-x. 9 git root 4096 10月 20 18:07 gitlab-rails drwx------. 2 git root 23 10月 20 18:06 gitlab-shell drwxr-x---. 2 git gitlab-www 51 10月 23 16:00 gitlab-workhorse drwx------. 3 root root 68 10月 23 16:10 logrotate drwxr-x---. 9 root gitlab-www 4096 10月 23 16:00 nginx drwxr-xr-x. 3 root root 31 10月 20 18:07 node-exporter drwx------. 2 gitlab-psql root 25 10月 20 18:08 postgres-exporter drwxr-xr-x. 3 gitlab-psql root 77 10月 23 16:00 postgresql drwxr-x---. 3 gitlab-prometheus root 38 10月 20 18:07 prometheus drwxr-x---. 2 gitlab-redis git 57 10月 23 16:47 redis -rw-r--r--. 1 root root 40 10月 20 17:18 trusted-certs-directory-hash
二、解決問題
2.1 猜測是可能磁碟空間不足,使用df -h 檢視磁碟空間
[[email protected] ~]# cd /var/opt/gitlab/
[[email protected] gitlab]# ll
總用量 16
drwx------. 3 git root 77 10月 23 17:03 backups
-rw-------. 1 root root 38 10月 20 18:07 bootstrapped
drwx------. 2 git root 44 10月 23 16:00 gitaly
drwx------. 3 git root 25 10月 23 16:47 git-data
drwxr-xr-x. 3 git root 19 10月 20 17:18 gitlab-ci
drwxr-xr-x. 2 git root 31 10月 20 18:08 gitlab-monitor
drwxr-xr-x. 9 git root 4096 10月 20 18:07 gitlab-rails
drwx------. 2 git root 23 10月 20 18:06 gitlab-shell
drwxr-x---. 2 git gitlab-www 51 10月 23 16:00 gitlab-workhorse
drwx------. 3 root root 68 10月 23 17:10 logrotate
drwxr-x---. 9 root gitlab-www 4096 10月 23 16:00 nginx
drwxr-xr-x. 3 root root 31 10月 20 18:07 node-exporter
drwx------. 2 gitlab-psql root 25 10月 20 18:08 postgres-exporter
drwxr-xr-x. 3 gitlab-psql root 77 10月 23 16:00 postgresql
drwxr-x---. 3 gitlab-prometheus root 38 10月 20 18:07 prometheus
drwxr-x---. 2 gitlab-redis git 57 10月 23 17:02 redis
-rw-r--r--. 1 root root 40 10月 20 17:18 trusted-certs-directory-hash
[[email protected] gitlab]# df -h
檔案系統 容量 已用 可用 已用% 掛載點
/dev/sda2 462G 197G 265G 43% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.8G 88K 3.8G 1% /dev/shm
tmpfs 3.8G 9.0M 3.8G 1% /run
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
tmpfs 775M 16K 775M 1% /run/user/42
tmpfs 775M 0 775M 0% /run/user/0
[[email protected] gitlab]#
從什麼的命令執行檢視,空間還是充足的,還有265G可用。
2.2 猜測GitLab備份包,解壓之後損壞了
將解密之後的Gitlab備份包和原始的Gitlab備份包對比,位元組數都是125403678720個位元組,檔案應該是沒有損壞。
2.3 猜測是不是 /var/opt/gitlab/backups 目錄的許可權不對勁?
檢視下/var/opt/gitlab/backups目錄的許可權和owner,如下所示:
[[email protected] gitlab-rails]# cd /var/opt/gitlab/backups/
[[email protected] backups]# ll
總用量 122464536
-rwxrwxrwx. 1 root root 125403678720 10月 23 15:33 1540263550_2018_10_23_9.4.3_gitlab_backup.tar
[[email protected] backups]# tar xf uploads.tar.gz -C /var/opt/gitlab/gitlab-rails/uploads
tar: uploads.tar.gz:無法 open: 沒有那個檔案或目錄
tar: Error is not recoverable: exiting now
[[email protected] backups]# cd ../
[[email protected] gitlab]# ll
總用量 16
drwxr-xr-x. 2 root root 58 10月 23 16:25 backups
-rw-------. 1 root root 38 10月 20 18:07 bootstrapped
drwx------. 2 git root 44 10月 23 16:00 gitaly
drwx------. 3 git root 25 10月 23 16:47 git-data
drwxr-xr-x. 3 git root 19 10月 20 17:18 gitlab-ci
drwxr-xr-x. 2 git root 31 10月 20 18:08 gitlab-monitor
drwxr-xr-x. 9 git root 4096 10月 20 18:07 gitlab-rails
drwx------. 2 git root 23 10月 20 18:06 gitlab-shell
drwxr-x---. 2 git gitlab-www 51 10月 23 16:00 gitlab-workhorse
drwx------. 3 root root 68 10月 23 16:10 logrotate
drwxr-x---. 9 root gitlab-www 4096 10月 23 16:00 nginx
drwxr-xr-x. 3 root root 31 10月 20 18:07 node-exporter
drwx------. 2 gitlab-psql root 25 10月 20 18:08 postgres-exporter
drwxr-xr-x. 3 gitlab-psql root 77 10月 23 16:00 postgresql
drwxr-x---. 3 gitlab-prometheus root 38 10月 20 18:07 prometheus
drwxr-x---. 2 gitlab-redis git 57 10月 23 16:47 redis
-rw-r--r--. 1 root root 40 10月 20 17:18 trusted-certs-directory-hash
[[email protected] gitlab]# chown git backups/
[[email protected] gitlab]# chmod 700 backups/
[[email protected] gitlab]# cd backups/
[[email protected] backups]# sudo gitlab-rake gitlab:backup:restore BACKUP=1540263550_2018_10_23_9.4.3
Unpacking backup ...
修改後的/var/opt/gitlab/backups目錄許可權和owner,如下所示:
[[email protected] gitlab]#
[[email protected] gitlab]#
[[email protected] gitlab]# pwd
/var/opt/gitlab
[[email protected]lhost gitlab]# ll
總用量 16
drwx------. 3 git root 77 10月 23 17:03 backups
-rw-------. 1 root root 38 10月 20 18:07 bootstrapped
drwx------. 2 git root 44 10月 23 16:00 gitaly
drwx------. 3 git root 25 10月 23 16:47 git-data
drwxr-xr-x. 3 git root 19 10月 20 17:18 gitlab-ci
drwxr-xr-x. 2 git root 31 10月 20 18:08 gitlab-monitor
drwxr-xr-x. 9 git root 4096 10月 20 18:07 gitlab-rails
drwx------. 2 git root 23 10月 20 18:06 gitlab-shell
drwxr-x---. 2 git gitlab-www 51 10月 23 16:00 gitlab-workhorse
drwx------. 3 root root 68 10月 23 17:10 logrotate
drwxr-x---. 9 root gitlab-www 4096 10月 23 16:00 nginx
drwxr-xr-x. 3 root root 31 10月 20 18:07 node-exporter
drwx------. 2 gitlab-psql root 25 10月 20 18:08 postgres-exporter
drwxr-xr-x. 3 gitlab-psql root 77 10月 23 16:00 postgresql
drwxr-x---. 3 gitlab-prometheus root 38 10月 20 18:07 prometheus
drwxr-x---. 2 gitlab-redis git 57 10月 23 17:17 redis
-rw-r--r--. 1 root root 40 10月 20 17:18 trusted-certs-directory-hash
[[email protected] gitlab]#
我才反應起來,之前我將/var/opt/gitlab目錄刪除了,然後用了root使用者新建了/var/opt/gitlab目錄,所以導致不一致。而Gitlab恢復操作使用的使用者是git,所以沒有許可權去操作root使用者新建的目錄。
修改好許可權和所屬使用者之後,再執行命令就正常進行了!