顯示具有 Backup 標籤的文章。 顯示所有文章
顯示具有 Backup 標籤的文章。 顯示所有文章

2019年10月1日 星期二

Gitlab 備份筆記


主要指令:
git-server@ubuntu:/opt/gitlab/bin$ gitlab-rake gitlab:backup:create
/usr/bin/gitlab-rake error: could not load /opt/gitlab/etc/gitlab-rails/gitlab-r                                                                                               ails-rc
Either you are not allowed to read the file, or it does not exist yet.
You can generate it with:   sudo gitlab-ctl reconfigure
git-server@ubuntu:/opt/gitlab/bin$ sudo gitlab-rake gitlab:backup:create
2019-10-07 15:16:40 +0800 -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2019-10-07 15:16:41 +0800 -- done
2019-10-07 15:16:41 +0800 -- Dumping repositories ...
 * yuching/ofco_ching (@hashed/4e/07/4e07408562bedb8b60ce05c1decfe3ad16b72230967                                                                                               de01f640b7e4729b49fce) ... [SKIPPED]
[SKIPPED] Wiki
 * yenpc/my_first_test (@hashed/79/02/7902699be42c8a8e46fbbb4501726517e86b22c56a                                                                                               189f7625a6da49081b2451) ... [DONE]
[SKIPPED] Wiki
 * sapido-iot/egssys (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a9                                                                                               09c162f7e470e581e278) ... [DONE]
[SKIPPED] Wiki

:::

2019-10-07 15:22:23 +0800 -- done
2019-10-07 15:22:23 +0800 -- Dumping lfs objects ...
2019-10-07 15:22:23 +0800 -- done
2019-10-07 15:22:23 +0800 -- Dumping container registry images ...
2019-10-07 15:22:23 +0800 -- [DISABLED]
Creating backup archive: 1570432943_2019_10_07_12.0.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.
有些需要手動備份的檔案

root@ubuntu:/var/opt/gitlab/backups# pwd
/var/opt/gitlab/backups

root@ubuntu:/var/opt/gitlab/backups# ls -al
total 20964304
drwx------  2 git  root        4096 Oct  7 15:24 .
drwxr-xr-x 21 root root        4096 Jul 31 15:14 ..
-rw-------  1 git  git  21467432960 Oct  7 15:24 1570432943_2019_10_07_12.0.3_gitlab_backup.tar
備份檔在此

\\192.168.88.16\GitlabBackup
User:backup
Password:R@Sns6
/mnt/nas/GitlabBackupFolder

Edit /etc/gitlab/gitlab.rb
1.gitlab_rails[`backup_path`] 的內容修改成 /mnt/nas/GitlabBackupFolder

/mnt/nas/GitlabBackupFolder/gitlab_backup

2. 仔細看裡面的設定,還可以設定備份的區間,太舊的會自動幫忙刪除。

執行以下指令,讓修改生效
gitlab-ctl reconfigure
gitlab-ctl restart

=======================================================
將NAS的CIFS sharing folder mount 到ubuntu
MOUNT_POINT=/mnt/nas/GitlabBackupFolder
SHARE_FOLDER=//192.168.88.16/GitlabBackup
DOMAIN=NASsrv01
USERNAME=backup
PASSWORD=****

mount -t cifs $SHARE_FOLDER $MOUNT_POINT -o username="$USERNAME",password="$PASSWORD",domain="$DOMAIN",iocharset=utf8,file_mode=0777,dir_mode=0777,vers=2.0

mount -t cifs //192.168.88.16/GitlabBackup /mnt/nas/GitlabBackupFolder -o username="backup",password="******",domain="NASsrv01",iocharset=utf8,file_mode=0777,dir_mode=0777,vers=2.0

mount -t cifs \\192.168.88.16\GitlabBackup /mnt/nas/GitlabBackupFolder -o username=backup,password="******",domain=NASsrv01,iocharset=utf8,file_mode=0777,dir_mode=0777,guest

// 這裡你也可以不用 guest, 可以使用 gid=xxxx 或 uid=xxxx 來指定給某個群組或個人, guest 只是比較偷懶的作法
// 如果遇到失敗可以檢查一下是否有套件沒裝到,再使用 apt-get install 安裝
// apt-get install nfs-common
// apt-get install cifs-utils

mount.cifs \\192.168.88.16\GitlabBackup GitlabBackupFolder -o username=backup

sudo mount -t cifs //192.168.88.16/GitlabBackup /mnt/nas/GitlabBackupFolder

git-server@ubuntu:/mnt/nas$ sudo mount -t cifs $SHARE_FOLDER $MOUNT_POINT -o username="$USERNAME",password="$PASSWORD",domain="$DOMAIN",iocharset=utf8,file_mode=0777,dir_mode=0777,guest,vers=2.0
git-server@ubuntu:/mnt/nas$ ls
GitlabBackupFolder
git-server@ubuntu:/mnt/nas$ cd GitlabBackupFolder/
git-server@ubuntu:/mnt/nas/GitlabBackupFolder$ ls
'#recycle'   test.txt
git-server@ubuntu:/mnt/nas/GitlabBackupFolder$

https://www.rootop.org/pages/4165.html
ubuntu挂载共享mount error(95): Operation not supported


 gitlab_rails['manage_backup_path'] = true
 gitlab_rails['backup_path'] = "/mnt/nas/GitlabBackupFolder"




Ran chmod 00700  returned 1
Ran chmod 00700  returned 1
chmod 00700 /mnt/nas/GitlabBackupFolder


STDERR: chmod: changing permissions of '': Operation not permitted
=======================================================

Cron Job 排程
sudo crontab -e
## Gitlab Backup
# Launch Gitlab backup service
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
# Copy Gitlab backup file to remote server
0 3 * * * find /var/opt/gitlab/backups/ -name "*gitlab_backup.tar" -mtime -1 -exec /bin/cp -a {} /mnt/nas/GitlabBackupFolder \;
# Retain backup data on local folder in 3 days
0 4 * * * find /var/opt/gitlab/backups/ -name "*gitlab_backup.tar" -mtime +1 -exec rm -rf {} \;
# Retain backup data on local folder in 7 days
0 5 * * * find /mnt/nas/GitlabBackupFolder/ -name "*gitlab_backup.tar" -mtime +7 -exec rm -rf {} \;
成功
=======================================================
find /var/opt/gitlab/backups/ -name "*gitlab_backup.tar" -mtime +1
find /mnt/nas/GitlabBackupFolder/ -name "*gitlab_backup.tar" -mtime +7 -exec rm -rf {} \;


要還原時主要步驟:
先安裝與之前備份時相同版本的 Gitlab
停止 gitlab 的服務
將要還原的備份檔放到 /var/opt/gitlab/backups/ 位置
下指令指定要還原的 TIME_STAMP 備份檔
啟動 gitlab, Create satellites, Check gitlab ... 完成

https://poychang.github.io/gitlab-backup/
Gitlab 備份筆記

http://mycodetub.logdown.com/posts/260395-gitlab-backup-restore-settings-notes
Gitlab 備份/還原設定筆記

Gitlab備份與恢復、遷移與升級
https://www.itread01.com/content/1527863887.html


mkdir -p /mnt/nas/GitlabBackupFolder2
mount -t nfs 192.168.88.16:/volume1/GitlabBackup2 /mnt/nas/GitlabBackupFolder2
mount:  can't find in /etc/fstab.

2017年10月18日 星期三

利用微軟作業系統內建指令XCOPY+Task Scheduler代替備份軟體

微軟作業系統內建指令XCOPY備份功能介紹
您是否曾遇到硬碟或隨身碟故障,導致檔案損壞的情況,此時才後悔沒備份。但備份工作既耗時又常碰到問題,有時備份到一半出現錯誤訊息,到底備份多少也不知道,還要重來!因此,介紹一個具有以下特色的備份方法。
不需購買或安裝軟體
可完全備份或只備份日期較新的檔案
備份的檔案如損壞可以跳過繼續備份其它檔案
可利用系統排程做定時備份
設計原理
建立一個批次執行檔(bat),裡面放一行Windows所提供的XCOPY指令,再加入適當的參數就可以輕鬆完成備份工作。
操作流程
1.執行記事本:點選[程式集]/[附屬應用程式]/[記事本]

2.輸入以下指令(可用複製/貼上功能再自行修改內容)
XCOPY . D:\隨身碟備份\ /D/K/E/Y/C/I/H (不要加H, 很麻煩)

來源:點號 . ,表示複製此批次執行檔所存放位置的所有檔案。
目的:D:\隨身碟備份\,表示複製到目的地為D碟的[隨身碟備份]資料夾內。
參數:/D/K/E/Y/C/I/H,/D只複製比目的檔還新的檔案,/K複製後檔案屬性不變,/E包含子目錄,/Y不要求確認,/C錯誤發生也繼續,/I目的不存在就建立資料夾,/H複製隱藏檔和系統檔。

3.將檔案存在您要備份的磁碟機或資料夾內(一定要切換存檔類型為所有檔案,且副檔名一定要輸入.bat)。


4.用檔案總管點兩下執行設計完成的批次檔(bat檔),開始進行備份工作。


5.往後要做備份,只要點兩下此批次檔即可,且備份速度比第一次快很多哦!(因為它只拷貝比目的檔還新的檔案)

6. 可用工作排程器加入固定排程

Windows XP排程設計
  以上提供的是半自動的備份方法,如果要完成全自動定時做備份的工作可以利用Windows內建的[排定的工作],定時執行我們所建立的批次執行檔(bat),完成定時備份的功能。操作流程如下:
操作流程
1.開啟[程式集]/[附屬應用程式]/[系統工具]/[排定的工作]。
2.點選[下一步] 。
3.按[瀏覽]挑選我們設計好要備份用的批次檔。
4.挑選工作執行的方式,例如:每日、每週、每月。
5.輸入開始時間。
6.輸入此電腦開機時所使用的帳號及密碼。
7.完成。

Example: 2022/05/23 and works
XCOPY D:\Backup\ERP-Backup\ERP*.* F:\ /D/K/E/Y/C/I
forfiles -p "F:" -s -m ERP*.* -d -14 -c "cmd /c del @PATH"

XCOPY指令詳解
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] ..........

source       指定要複製的檔案。
destination  指定位置或者/以及新檔案的名稱。
/A    只複製設定成保存屬性的檔案,不要改變屬性的設定。
/M    只複製設定成保存屬性的檔案,並清除保存屬性。
/D:m-d-y  複製指定日期當天或之後變更的檔案。如果沒給日期,只複製那些來源檔案日期比目的檔案日期為新的檔案。
/EXCLUDE:file1[+file2][+file3]...
        指定檔案清單字串。每個字串應在不同行。如果有字串對應到要進行複製的檔案絕
        對路徑的任何部分,這個檔案會被排除複製。例如,指定字串
        \obj\ 或 .obj 的話,會排除所有在 obj 目錄下副檔名是.obj 的檔案複製。
/P    在建立每個目的檔案時顯示提示。
/S    複製每個目錄及其包含的子目錄,不複製空目錄。
/E    複製每個目錄及其包含的子目錄,也複製空目錄。/S 與 /E相同,能夠用來修改 /T。
/V    驗證每個新檔案。
/W    在複製之前提示您按鍵繼續。
/C    如果錯誤發生時也繼續複製。
/I    如果目的不存在且複製一個以上的檔案的話,就假設指定的目的一定是目錄。
/Q    在複製時不要顯示檔名。
/F    在複製時顯示來源及目的檔案的全部檔名。
/L    顯示要複製的檔案。
/G    允許加密檔案複製到不支援加密的目的地。
/H    複製隱藏檔和系統檔。
/R    覆蓋唯讀檔案。
/T    建立目錄結構,但不複製其中的檔案。不包括空目錄及子目錄。
      /T /E 會包括空目錄及子目錄。
/U    只複製已經存在目的位置的檔案。
/K    複製檔案屬性。通常 Xcopy 會重設唯讀的屬性。
/N    用所產生的短檔名來進行複製。
/O    複製檔案所有權及 ACL 資訊。
/X    複製檔案審查設定 (包含 /O)。
/Y    不要提示您確認是否要覆蓋一個已經存在的檔案。
/-Y    示您確認是否要覆蓋一個已經存在的檔案。
/Z    在可重新開始的模式中複製網路檔案。

Docker Command

#1 pull images $docker pull chusiang/takaojs1607 #2 list images $docker images #3.1 run docker $docker run -it ### bash #3.2 run do...