add backup guide

This commit is contained in:
EricTYL 2019-11-22 11:05:03 +08:00
parent afb5b08dde
commit bce094e140
3 changed files with 290 additions and 2 deletions

View File

@ -1,9 +1,20 @@
# Ubuntu 18.04 LTS 安裝 R4.5 標準流程 # Ubuntu 18.04 LTS 安裝 R4.5 標準流程
## 前置作業 ## 前置作業
* Ubuntu 18.04 LTS 已安裝完畢並能遠端連線進入 * Ubuntu 18.04 LTS 已安裝完畢並能遠端連線進入
* 當前帳號可以使用 sudo 指令 * 當前帳號可以使用 sudo 指令
## 建立 rulingcom 帳號(若已是 rulingcom 帳號,前往下一步驟)
```sh
$ sudo su # 從當前帳號切換到 root
$ adduser rulingcom
$ # set the password for rulingcom
$ # fill in user information, it's ok to leave all blank
$ usermod -aG sudo rulingcom # 讓 rulingcom 可用 sudo
$ su - rulingcom
$ sudo ls -la /root # 測試 rulingcom sudo 是否可用
$ exit; exit # 第一次 exit 退回 root 帳號,第二次 exit 退回剛登入的帳號
```
## 安裝 Nginx 1.14 ## 安裝 Nginx 1.14
```sh ```sh
$ sudo apt update $ sudo apt update
@ -15,7 +26,6 @@ $ cd /etc/nginx/
$ sudo mkdir orbit_sites/ $ sudo mkdir orbit_sites/
$ sudo vim orbit_sites/xxx_ooo # 建立網站 nginx 設定檔xxx 為學校縮寫ooo 為系所、單位縮寫。內容參考附註 nginx 設定檔 $ sudo vim orbit_sites/xxx_ooo # 建立網站 nginx 設定檔xxx 為學校縮寫ooo 為系所、單位縮寫。內容參考附註 nginx 設定檔
``` ```
```nginx ```nginx
# 此為附註 nginx 設定檔 # 此為附註 nginx 設定檔
# upstream xxx_sock { # upstream xxx_sock {
@ -103,3 +113,88 @@ $ bundle exec unicorn_rails -c config/unicorn.rb -D -E production
$ sudo service nginx restart $ sudo service nginx restart
$ # Login the new create site with rulingcom account and choose “Admin Area” to complete the registration of this new created site. $ # Login the new create site with rulingcom account and choose “Admin Area” to complete the registration of this new created site.
``` ```
## 設定備份(以備份一週內容為例)
### 一、資料庫備份
```sh
$ sudo crontab -e
# 內容如下:
# 0 3 * * * mongodump -o /home/backup/db/`date "+\%Y\%m\%d"`_db
# 0 4 * * * rm -fr /home/backup/db/`date --date="1 week ago" "+\%Y\%m\%d"`_db
```
### 二、R4.5 網站目錄備份
```sh
# 安裝 rsnapshot如已安裝則直接編輯 /etc/rsnapshot.conf
$ sudo apt-get install rsnapshot -y
$ sudo vim /etc/rsnapshot.conf # 內容建附註 rsnapshot
$ sudo mkdir /home/backup
$ sudo mkdir /home/backup/orbit
$ sudo chmod 777 /home/backup/orbit
$ rsnapshot -t daily # 測試是否設定正確
```
```txt
# 此為附註 rsnapshot
# 注意!該檔使用 tab 而非 space
# find BACKUP LEVELS /INTERVALS part
# at this part, remove every lines with `retain` and then add the line below:
retain daily 7
# find SNAPSHOT ROOT DIRECTORY part
# modify the snapshot dir path
snapshot_root /home/backup/orbit
# find BACKUP POINTS / SCRIPTS part
# add R4.5 site backup
backup /home/rulingcom localhost/
```
### 三、定期壓縮與刪除 log
```sh
$ sudo vim /etc/logrotate.d/orbit # 內容見附註 logrotate
$ sudo logrotate -d /etc/logrotate.conf # 確認系統是否有使用 /etc/logrotate.d/orbit
```
```txt
# 附註 logrotate
/home/rulingcom/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/home/rulingcom/*/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/var/log/mongodb/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /var/lib/mongodb/mongod.lock ] || kill -SIGUSR1 `cat /var/lib/mongodb/mongod.lock`
endscript
}
```

View File

@ -25,6 +25,18 @@
當前帳號可以使用 sudo 指令 當前帳號可以使用 sudo 指令
</li> </li>
</ul> </ul>
<h2 id="rulingcom-rulingcom">
建立 rulingcom 帳號(若已是 rulingcom 帳號,前往下一步驟)
</h2>
<pre><code class="sh">$ sudo su # 從當前帳號切換到 root
$ adduser rulingcom
$ # set the password for rulingcom
$ # fill in user information, it's ok to leave all blank
$ usermod -aG sudo rulingcom # 讓 rulingcom 可用 sudo
$ su - rulingcom
$ sudo ls -la /root # 測試 rulingcom sudo 是否可用
$ exit; exit # 第一次 exit 退回 root 帳號,第二次 exit 退回剛登入的帳號
</code></pre>
<h2 id="nginx-114"> <h2 id="nginx-114">
安裝 Nginx 1.14 安裝 Nginx 1.14
</h2> </h2>
@ -124,6 +136,89 @@ $ RAILS_ENV=production bundle exec rake assets:precompile
$ bundle exec unicorn_rails -c config/unicorn.rb -D -E production $ bundle exec unicorn_rails -c config/unicorn.rb -D -E production
$ sudo service nginx restart $ sudo service nginx restart
$ # Login the new create site with rulingcom account and choose “Admin Area” to complete the registration of this new created site. $ # Login the new create site with rulingcom account and choose “Admin Area” to complete the registration of this new created site.
</code></pre>
<h2 id="_2">
設定備份(以備份一週內容為例)
</h2>
<h3 id="_3">
一、資料庫備份
</h3>
<pre><code class="sh">$ sudo crontab -e
# 內容如下:
# 0 3 * * * mongodump -o /home/backup/db/`date "+\%Y\%m\%d"`_db
# 0 4 * * * rm -fr /home/backup/db/`date --date="1 week ago" "+\%Y\%m\%d"`_db
</code></pre>
<h3 id="r45_1">
二、R4.5 網站目錄備份
</h3>
<pre><code class="sh"># 安裝 rsnapshot如已安裝則直接編輯 /etc/rsnapshot.conf
$ sudo apt-get install rsnapshot -y
$ sudo vim /etc/rsnapshot.conf # 內容建附註 rsnapshot
$ sudo mkdir /home/backup
$ sudo mkdir /home/backup/orbit
$ sudo chmod 777 /home/backup/orbit
$ rsnapshot -t daily # 測試是否設定正確
</code></pre>
<pre><code class="txt"># 此為附註 rsnapshot
# 注意!該檔使用 tab 而非 space
# find BACKUP LEVELS /INTERVALS part
# at this part, remove every lines with `retain` and then add the line below:
retain daily 7
# find SNAPSHOT ROOT DIRECTORY part
# modify the snapshot dir path
snapshot_root /home/backup/orbit
# find BACKUP POINTS / SCRIPTS part
# add R4.5 site backup
backup /home/rulingcom localhost/
</code></pre>
<h3 id="log">
三、定期壓縮與刪除 log
</h3>
<pre><code class="sh">$ sudo vim /etc/logrotate.d/orbit # 內容見附註 logrotate
$ sudo logrotate -d /etc/logrotate.conf # 確認系統是否有使用 /etc/logrotate.d/orbit
</code></pre>
<pre><code class="txt"># 附註 logrotate
/home/rulingcom/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/home/rulingcom/*/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/var/log/mongodb/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /var/lib/mongodb/mongod.lock ] || kill -SIGUSR1 `cat /var/lib/mongodb/mongod.lock`
endscript
}
</code></pre> </code></pre>
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/highlight.min.js"> <script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/highlight.min.js">
</script> </script>

View File

@ -2,6 +2,19 @@
## 前置作業 ## 前置作業
* Ubuntu 18.04 LTS 已安裝完畢並能遠端連線進入 * Ubuntu 18.04 LTS 已安裝完畢並能遠端連線進入
* 當前帳號可以使用 sudo 指令 * 當前帳號可以使用 sudo 指令
## 建立 rulingcom 帳號(若已是 rulingcom 帳號,前往下一步驟)
```sh
$ sudo su # 從當前帳號切換到 root
$ adduser rulingcom
$ # set the password for rulingcom
$ # fill in user information, it's ok to leave all blank
$ usermod -aG sudo rulingcom # 讓 rulingcom 可用 sudo
$ su - rulingcom
$ sudo ls -la /root # 測試 rulingcom sudo 是否可用
$ exit; exit # 第一次 exit 退回 root 帳號,第二次 exit 退回剛登入的帳號
```
## 安裝 Nginx 1.14 ## 安裝 Nginx 1.14
```sh ```sh
$ sudo apt update $ sudo apt update
@ -99,4 +112,89 @@ $ RAILS_ENV=production bundle exec rake assets:precompile
$ bundle exec unicorn_rails -c config/unicorn.rb -D -E production $ bundle exec unicorn_rails -c config/unicorn.rb -D -E production
$ sudo service nginx restart $ sudo service nginx restart
$ # Login the new create site with rulingcom account and choose “Admin Area” to complete the registration of this new created site. $ # Login the new create site with rulingcom account and choose “Admin Area” to complete the registration of this new created site.
```
## 設定備份(以備份一週內容為例)
### 一、資料庫備份
```sh
$ sudo crontab -e
# 內容如下:
# 0 3 * * * mongodump -o /home/backup/db/`date "+\%Y\%m\%d"`_db
# 0 4 * * * rm -fr /home/backup/db/`date --date="1 week ago" "+\%Y\%m\%d"`_db
```
### 二、R4.5 網站目錄備份
```sh
# 安裝 rsnapshot如已安裝則直接編輯 /etc/rsnapshot.conf
$ sudo apt-get install rsnapshot -y
$ sudo vim /etc/rsnapshot.conf # 內容建附註 rsnapshot
$ sudo mkdir /home/backup
$ sudo mkdir /home/backup/orbit
$ sudo chmod 777 /home/backup/orbit
$ rsnapshot -t daily # 測試是否設定正確
```
```txt
# 此為附註 rsnapshot
# 注意!該檔使用 tab 而非 space
# find BACKUP LEVELS /INTERVALS part
# at this part, remove every lines with `retain` and then add the line below:
retain daily 7
# find SNAPSHOT ROOT DIRECTORY part
# modify the snapshot dir path
snapshot_root /home/backup/orbit
# find BACKUP POINTS / SCRIPTS part
# add R4.5 site backup
backup /home/rulingcom localhost/
```
### 三、定期壓縮與刪除 log
```sh
$ sudo vim /etc/logrotate.d/orbit # 內容見附註 logrotate
$ sudo logrotate -d /etc/logrotate.conf # 確認系統是否有使用 /etc/logrotate.d/orbit
```
```txt
# 附註 logrotate
/home/rulingcom/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/home/rulingcom/*/*/*/log/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
endscript
}
/var/log/mongodb/*.log {
daily
rotate 7
compress
missingok
notifempty
create 644 rulingcom rulingcom
postrotate
[ ! -f /var/lib/mongodb/mongod.lock ] || kill -SIGUSR1 `cat /var/lib/mongodb/mongod.lock`
endscript
}
``` ```