<<編程基礎(chǔ)-語言SQL.Git.Docker>>

<<編程基礎(chǔ)-語言SQL.Git.Docker>>
SQL.PLSQL
http://docs.pythontab.com
https://springcloud.cc/
https://echo.labstack.com/
https://beego.me/
http://flask.pocoo.org/
https://www.programcreek.com/
概述: 主要存放新產(chǎn)品研發(fā)的架構(gòu)部署,架構(gòu)解決方案,持續(xù)集成,持續(xù)部署和自動(dòng)化的一些資料等。
############################################################################
use log_dev database, change your table name and timestamp day value, and excute it
select log_cd,func_cd,log_dhms from log_operate_1709 where created_date >= to_timestamp('2017-09-11', 'yyyy-mm-dd')
and log_cd <> '日志類型' order BY created_date DESC;
select log_cd,func_cd,log_dhms,infurl,infnm from log_pdt_data_1709 where created_date >= to_timestamp('2017-09-11', 'yyyy-mm-dd')
and log_cd <> '日志類型' ORDER BY created_date DESC;
--testing log SQL statements
select log_cd,func_cd,log_dhms,from_ip from log_operate_1709 where
created_date >= to_timestamp('2017-09-14', 'yyyy-mm-dd')
and log_cd <> '日志類型' order BY created_date DESC;
select log_cd,func_cd,log_dhms,infurl,infnm,from_ip from log_pdt_data_1709 where
created_date >= to_timestamp('2017-09-14', 'yyyy-mm-dd')
and log_cd <> '日志類型' ORDER BY created_date DESC;
--count log_operate_1709 and log_pdt_data_1709 tables current date record
select count(log_cd) from log_operate_1709 where log_cd <> '日志類型' and
created_date >= to_timestamp('2017-09-14', 'yyyy-mm-dd');
select count(log_cd) from log_pdt_data_1709 where log_cd <> '日志類型' and
created_date >= to_timestamp('2017-09-14', 'yyyy-mm-dd');
#################################################################################################################
白盒測試 需求用例 名詞解釋 houseblock鎖房 RT+ 只改房含 RT* 不管改不改房含 只要改了房價(jià) noshow 預(yù)定未到 結(jié)賬folio 就是結(jié)賬賬單-已結(jié)賬下面 下個(gè)+下面的
001.房價(jià)=====================================================
每日房價(jià)記錄數(shù)與住店時(shí)間一致
houseblock記錄數(shù)與住店時(shí)間一致
每日收取的房含要出現(xiàn)在每日房含表中的每一天,首日房含只能出現(xiàn)在首日
一期所有每日房價(jià)的價(jià)格代碼、折扣一樣
RT+只能有一套房含
RT只能有一套房含,且每日價(jià)格設(shè)定一樣
002.預(yù)訂=====================================================
沒有來期大于等于今日的noshow賬戶
沒有離期小于今日的在店賬戶
沒有來期小于今日的預(yù)訂賬戶
沒有來期大于今日的在店賬戶
每個(gè)賬戶至少有一個(gè)住店客人,且賬戶表里的住店客人ID對應(yīng)的存在
每個(gè)賬戶只能有一個(gè)預(yù)訂人,且賬戶表里的預(yù)訂人ID對應(yīng)的存在
003.賬務(wù)====================================================
客賬交易金額與賬務(wù)明細(xì)金額一致,12個(gè)細(xì)項(xiàng)金額也一致
賬單的余額為0
已結(jié)賬戶余額為0
結(jié)賬folio里的幾個(gè)金額與明細(xì)一致
轉(zhuǎn)賬folio里的幾個(gè)金額與明細(xì)一致
004.客房====================================================
空房態(tài)沒有在店賬戶
占用房態(tài)必有在店賬戶
維修房態(tài)有對應(yīng)的維修記錄
houseblock
###################################################################
白盒測試 by 20170622
房價(jià) housingprice_test001 housingprice_test002 housingprice_test003
1.每日房價(jià)記錄數(shù)與住店時(shí)間一致
SELECT country, SUM( CASE WHEN sex = '1' THEN population ELSE 0 END), --男性人口 SUM( CASE WHEN sex = '2' THEN population ELSE 0 END) --女性人口 FROM Table_A GROUP BY country
2.houseblock記錄數(shù)與住店時(shí)間一致
select * from emp where empno=7369 for update;
3.每日收取的房含要出現(xiàn)在每日房含表中的每一天,首日房含只能出現(xiàn)在首日
select * from emp where empno=7369 for update;
4.一期所有每日房價(jià)的價(jià)格代碼、折扣一樣
select * from emp where empno=7369 for update;
5.RT+只能有一套房含
select * from emp where empno=7369 for update;
6.RT
只能有一套房含,且每日價(jià)格設(shè)定一樣
select * from emp where empno=7369 for update;
7.每日房含12個(gè)分項(xiàng)的合計(jì)與每日房價(jià)的一致
select * from emp where empno=7369 for update;

預(yù)訂 reserve_test001 reserve_test002
1.沒有來期大于等于今日的noshow賬戶
SELECT arr_dt,dpt_dt,acct_no,resv_no FROM rsv_account WHERE acct_stus='NSW' AND arr_dt>今日
2.沒有離期小于今日的在店賬戶
SELECT arr_dt,dpt_dt,acct_no,resv_no FROM rsv_account WHERE acct_stus='STY' AND dpt_dt<今日
3.沒有來期小于今日的預(yù)訂賬戶
SELECT arr_dt,dpt_dt,acct_no,resv_no FROM rsv_account WHERE acct_stus='RSV' AND arr_dt<今日
4.沒有來期大于今日的在店賬戶

SELECT arr_dt,dpt_dt,acct_no,resv_no FROM rsv_account WHERE acct_stus='STY' AND arr_dt>今日
5.每個(gè)賬戶至少有一個(gè)住店客人,且賬戶表里的住店客人ID對應(yīng)的存在

SELECT resv_no,acct_no,acct_stus FROM rsv_account WHERE acct_stus IN ('RSV','STY','WAT') AND resv_no NOT IN ( SELECT DISTINCT(M.resv_no) FROM rsv_account M INNER JOIN rsv_account_guest D ON M.resv_no=D.resv_no AND M.acct_no=D.acct_no WHERE acct_stus IN ('RSV','STY','WAT') AND guest_flg='RE' ORDER BY M.resv_no)
6.每個(gè)賬戶只能有一個(gè)預(yù)訂人,且賬戶表里的預(yù)訂人ID對應(yīng)的存在

(SELECT guest_id FROM rsv_account m INNER JOIN rsv_account_guest d ON m.resv_no=d.resv_no AND m.bkguest_id=d.guest_id WHERE acct_stus IN ('RSV','STY','WAT') AND guest_flg='BK'
ORDER BY m.resv_no,d.acct_no)
SELECT acct_stus,resv_no,acct_no FROM rsv_account WHERE acct_stus IN ('RSV','STY','WAT') AND acct_no IN ( SELECT d.acct_no FROM rsv_account m INNER JOIN rsv_account_guest d ON m.resv_no=d.resv_no AND m.acct_no=d.acct_no WHERE acct_stus IN ('RSV','STY','WAT') AND guest_flg='BK' GROUP BY d.acct_no HAVING COUNT(*)>1)

賬務(wù) financial_test001 financial_test002

1.客賬交易金額與賬務(wù)明細(xì)金額一致,12個(gè)細(xì)項(xiàng)金額也一致
金額一致:
SELECT * from (SELECT mtrn_id,SUM(trntot_amt) as amt1 FROM hpt_fin_transaction GROUP BY mtrn_id) A, (SELECT trn_id,SUM(trn_amt) as amt2 FROM hpt_fin_transaction_jrnl WHERE jrnl_typ='REVN' GROUP BY trn_id) B WHERE A.mtrn_id=B.trn_id AND amt1<>amt2
細(xì)項(xiàng)一致:
SELECT * FROM (SELECT mtrn_id,acct_no,room_num,trn_cd,trn_drpt,trntot_amt AS amt1,trn_net+trn_tax1+trn_tax2+trn_tax3+trn_tax4+trn_tax5+trnsvc_net+trnsvc_tax1+trnsvc_tax2+trnsvc_tax3+trnsvc_tax4+trnsvc_tax5 AS amt2 FROM hpt_fin_transaction) A WHERE A.amt1<>A.amt2
2.賬單的余額為0
SELECT acct_no,bill_no,SUM(trntot_amt) from hpt_fin_transaction WHERE COALESCE(bill_no,'')<>'' GROUP BY acct_no,bill_no HAVING SUM(trntot_amt)>0 ORDER BY acct_no
3.已結(jié)賬戶余額為0
SELECT a.acct_no,SUM(trntot_amt) from rsv_account a LEFT JOIN hpt_fin_transaction t ON a.acct_no=t.acct_no WHERE a.acct_stus='OUT' GROUP BY a.acct_no HAVING SUM(trntot_amt)>0
4.結(jié)賬folio里的幾個(gè)金額與明細(xì)一致
SELECT F.acct_no,F.folio_no,credit_amt,debit_amt,check_amt,T.acct_no,T.bill_no,T.normal,trnamt FROM hpt_fin_folio F LEFT JOIN (SELECT acct_no,bill_no,normal,sum(trntot_amt) AS trnamt FROM hpt_fin_transaction WHERE bill_no<>'' GROUP BY acct_no,bill_no,normal ORDER BY acct_no,bill_no) T ON F.acct_no=T.acct_no AND F.folio_no=T.bill_no WHERE F.folio_typ='BILL' AND COALESCE(credit_amt,0)<>COALESCE(debit_amt,0) OR CASE T.normal WHEN 'C' THEN COALESCE(debit_amt,0)<>trnamt WHEN 'D' THEN COALESCE(credit_amt,0)<>trnamt ELSE 1=1 END

5.轉(zhuǎn)賬folio里的幾個(gè)金額與明細(xì)一致
SELECT F.acct_no,F.folio_typ,F.folio_no,credit_amt,debit_amt,check_amt,J.trn_amt from hpt_fin_folio F LEFT JOIN (SELECT acct_no,pkgfolio_no,sum(trn_amt) AS trn_amt FROM hpt_fin_transaction_jrnl WHERE jrnl_typ='MOVE' GROUP BY acct_no,pkgfolio_no ORDER BY acct_no,pkgfolio_no) J ON F.acct_no=J.acct_no AND F.folio_no=J.pkgfolio_no WHERE F.folio_typ='MVIN' OR F.folio_typ='MVOUT' AND (COALESCE(credit_amt,0)+COALESCE(debit_amt,0)<>COALESCE(check_amt,0) OR COALESCE(check_amt,0)<>COALESCE(trn_amt,0))
SELECT F.acct_no,F.folio_typ,F.folio_no,credit_amt,debit_amt,check_amt,J.normal,J.trn_amt from hpt_fin_folio F LEFT JOIN (SELECT acct_no,pkgfolio_no,normal,sum(trn_amt) AS trn_amt FROM hpt_fin_transaction_jrnl WHERE jrnl_typ='MOVE' GROUP BY acct_no,pkgfolio_no,normal ORDER BY acct_no,pkgfolio_no,normal) J ON F.acct_no=J.acct_no AND F.folio_no=J.pkgfolio_no WHERE F.folio_typ='MVIN' OR F.folio_typ='MVOUT' AND CASE J.normal WHEN 'C' THEN COALESCE(credit_amt,0)<>J.trn_amt WHEN 'D' THEN COALESCE(debit_amt,0)<>J.trn_amt ELSE 1=1 END

客房 hotelroom_test001 hotelroom_test002
1.空房態(tài)沒有在店賬戶
SELECT arr_dt,dpt_dt,resv_no,acct_no,room_num FROM rsv_account WHERE acct_stus='STY' AND room_num IN (SELECT room_num FROM hpt_hk_room WHERE fo_room_stus='V')
2.占用房態(tài)必有在店賬戶
SELECT arr_dt,dpt_dt,resv_no,acct_no,room_num FROM rsv_account WHERE acct_stus='STY' AND room_num IN (SELECT room_num FROM hpt_hk_room WHERE fo_room_stus<>'O')
3.維修房態(tài)有對應(yīng)的維修記錄
SELECT room_num FROM hpt_hk_room WHERE room_stus='OOO' AND room_num NOT IN (SELECT room_num FROM hpt_hk_room_repair WHERE repair_typ='OOO' AND start_dt<=當(dāng)日 AND end_dt>=當(dāng)日)
apache-tomcat-9.0.0.M20

zookeeper-3.4.8

rabbitMq-3.6.1

erlang-18.3

redis-3.2.1

FastDFS-5.05

PostgreSQL 9.6.1

Node 6.9.1 NPM 3.10.10

[圖片上傳失敗...(image-ad7bda-1510734227417)]

PostgreSQL自帶一個(gè)客戶端pgAdmin,里面有個(gè)備份,恢復(fù)選項(xiàng),也能對數(shù)據(jù)庫進(jìn)行備份 恢復(fù)(還原),但最近發(fā)現(xiàn)數(shù)據(jù)庫慢慢龐大的時(shí)候,經(jīng)常出錯(cuò),備份的文件過程中出錯(cuò)的幾率那是相當(dāng)大,手動(dòng)調(diào)節(jié)灰常有限。所以一直尋找完美的備份恢復(fù)方案。

一: 純文件格式的腳本:

示例:

1. 只導(dǎo)出postgres數(shù)據(jù)庫的數(shù)據(jù),不包括模式 -s

pg_dump -U postgres -f /postgres.sql -s postgres(數(shù)據(jù)庫名)

2. 導(dǎo)出postgres數(shù)據(jù)庫(包括數(shù)據(jù))

pg_dump -U postgres -f /postgres.sql postgres(數(shù)據(jù)庫名)

3. 導(dǎo)出postgres數(shù)據(jù)庫中表test01的數(shù)據(jù)

create database "test01" with owner="postgres" encoding='utf-8';(單引號,雙引號不能錯(cuò))

pg_dump -U postgres -f /postgres.sql -t test01 postgres(數(shù)據(jù)庫名)

4. 導(dǎo)出postgres數(shù)據(jù)庫中表test01的數(shù)據(jù),以insert語句的形式

pg_dump -U postgres -f /postgres.sql -t test01 --column-inserts postgres(數(shù)據(jù)庫名)

5. 恢復(fù)數(shù)據(jù)到bk01數(shù)據(jù)庫

psql -U postgres -f /postgres.sql bk01

二、 使用歸檔文件格式:

pg_restore

使用pg_restore純文本恢復(fù)純文本格式的腳本,無法恢復(fù)

[root@localhost postgres-9.3.5]# pg_restore -U postgres -d bk01 /mnt/hgfs/window&ubuntu\ shared\ folder/vendemo.sql

pg_restore: [archiver] input file appears to be a text format dump. Please use psql.

pg_restore和歸檔文件格式一起使用重建數(shù)據(jù)庫。

1. 先備份:

pg_dump -U postgres -F t -f /vendemo.tar vendemo 備份下來有800多k

. 恢復(fù):

pg_restore -U postgres -d bk01 /vendemo.tar

2. 先備份:

pg_dump -U postgres -F c -f /vendemo.tar vendemo 備份下來有300多k

. 恢復(fù):

pg_restore -U postgres -d bk01 /vendemo.tar

三、 壓縮備份與恢復(fù):

處理

大數(shù)據(jù)

庫:

1. 使用壓縮的轉(zhuǎn)儲. 使用你熟悉的壓縮程序,比如說 gzip。

. 先備份:

pg_dump -U postgres vendemo | gzip > /vendemo.gz 備份下來只有30多k

. 恢復(fù):

gunzip -c /vendemo.gz | psql -U postgres bk02

或者

cat /vendemo.gz | gunzip | psql -U postgres bk02

2. 使用 split。. split 命令允許你 你用下面的方法把輸出分解成

操作系統(tǒng)

可以接受的大小。 比如,讓每個(gè)塊大小為 1 兆字節(jié):

. 先備份:

pg_dump -U postgres -d vendemo | split -b 100k - /vend/vend

導(dǎo)出來的樣子是 vendaa 100k

vendab 100k

vendac 100k

vendad 16k

. 恢復(fù):

cat /vend/vend* | psql -U postgres bk02

夢里尋他千百度,伊人卻在燈火闌珊處...其實(shí)PostgreSQL內(nèi)置不少的工具,尋找的備份恢復(fù)方案就在其中:pg_dump,psql。這兩個(gè)指令 在數(shù)據(jù)庫的安裝目錄下,比如我自己本地安裝的,路徑形如:C:\Program Files\PostgreSQL\9.5\;然后進(jìn)入到bin文件夾,會(huì)看到不少的exe文件,這就是PostgreSQL內(nèi)置的工具了。里面會(huì)找到 pg_dump.exe,psql.exe兩個(gè)文件。我們怎么用他們?

用法:

備份數(shù)據(jù)庫

,指令如下:

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">pg_dump -h 164.82.233.54 -U postgres databasename > C:\databasename.bak</pre>

開始-運(yùn)行-cmd 彈出dos控制臺;然后 在控制臺里,進(jìn)入PostgreSQL安裝目錄bin下:

cd C:\Program Files\PostgreSQL\9.0\bin

最后執(zhí)行備份指令:

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">pg_dump -h 164.82.233.54 -U postgres databasename > C:\databasename.bak</pre>

指令解釋:如上命令,pg_dump 是備份數(shù)據(jù)庫指令,164.82.233.54是數(shù)據(jù)庫的ip地址(必須保證數(shù)據(jù)庫允許外部訪問的權(quán)限哦~),當(dāng)然本地的數(shù)據(jù)庫ip寫 localhost;postgres 是數(shù)據(jù)庫的用戶名;databasename 是數(shù)據(jù)庫名。> 意思是導(dǎo)出到C:\databasename.bak文件里,如果沒有寫路徑,單單寫databasename.bak文件名,那么備份文件會(huì)保存在C: \Program Files\PostgreSQL\9.0\bin 文件夾里。

恢復(fù)數(shù)據(jù)庫 ,指令如下:

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">**psql -h localhost -U postgres -d databasename < C:\databasename.bak(測試沒有成功)

pg_restore.exe --host localhost --port 5432 --username "postgres" --dbname "symbolmcnew" --no-password --verbose "databasename.backup"(測試成功)** </pre>

指令解釋:如上命令,psql是恢復(fù)數(shù)據(jù)庫命令,localhost是要恢復(fù)到哪個(gè)數(shù)據(jù)庫的地址,當(dāng)然你可以寫上ip地址,也就是說能遠(yuǎn)程恢復(fù)(必須保證 數(shù)據(jù)庫允許外部訪問的權(quán)限哦~);postgres 就是要恢復(fù)到哪個(gè)數(shù)據(jù)庫的用戶;databasename 是要恢復(fù)到哪個(gè)數(shù)據(jù)庫。< 的意思是把C:\databasename.bak文件導(dǎo)入到指定的數(shù)據(jù)庫里。

以上所有的是針對windows而言的,如果在linux下,會(huì)不會(huì)有效?

在linux里依然有效。有一個(gè)值得注意的是:如果直接進(jìn)入PostgreSQL的安裝目錄bin下,執(zhí)行命令,可能會(huì)出現(xiàn) 找不到pg_dump,psql?的現(xiàn)象,我們在可以這樣:

備份

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">/opt/PostgreSQL/9.5/bin/pg_dump -h 164.82.233.54 -U postgres databasename > databasename.bak</pre>

恢復(fù)

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">/opt/PostgreSQL/9.5/bin/psql -h localhost -U postgres -d databasename < databasename.bak</pre>

##########################MYSQL DUMP Restore###############################

mysqldump命令式備份整個(gè)DB用的。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">shell> mysqldump *db_name* > *backup-file.sql*
</pre>

把備份的數(shù)據(jù)導(dǎo)入空數(shù)據(jù)庫的命令。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">shell> mysql *db_name* < *backup-file.sql*
</pre>

或者下面的這個(gè)命令。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">shell> mysql -e "source */path-to-backup/backup-file.sql*" *db_name*</pre>

在使用上面的命令的時(shí)候有可能會(huì)報(bào)版本不對。

原因是Linux中mysql命令的版本和你想導(dǎo)入的那個(gè)數(shù)據(jù)庫的版本不一致。

變通做法是跑到數(shù)據(jù)庫的bin目錄下面。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">sshell> ./mysqldump *db_name* > *backup-file.sql*</pre>

把備份的數(shù)據(jù)導(dǎo)入空數(shù)據(jù)庫的命令。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">shell> ./mysql *db_name* < *backup-file.sql*</pre>
apache-tomcat-9.0.0.M20

zookeeper-3.4.8

rabbitMq-3.6.1

erlang-18.3

redis-3.2.1

FastDFS-5.05

PostgreSQL 9.6.1

Node 6.9.1 NPM 3.10.10

[圖片上傳中...(image-2435c1-1510734229120-0)]

PostgreSQL自帶一個(gè)客戶端pgAdmin,里面有個(gè)備份,恢復(fù)選項(xiàng),也能對數(shù)據(jù)庫進(jìn)行備份 恢復(fù)(還原),但最近發(fā)現(xiàn)數(shù)據(jù)庫慢慢龐大的時(shí)候,經(jīng)常出錯(cuò),備份的文件過程中出錯(cuò)的幾率那是相當(dāng)大,手動(dòng)調(diào)節(jié)灰常有限。所以一直尋找完美的備份恢復(fù)方案。

一: 純文件格式的腳本:

示例:

1. 只導(dǎo)出postgres數(shù)據(jù)庫的數(shù)據(jù),不包括模式 -s

pg_dump -U postgres -f /postgres.sql -s postgres(數(shù)據(jù)庫名)

2. 導(dǎo)出postgres數(shù)據(jù)庫(包括數(shù)據(jù))

pg_dump -U postgres -f /postgres.sql postgres(數(shù)據(jù)庫名)

3. 導(dǎo)出postgres數(shù)據(jù)庫中表test01的數(shù)據(jù)

create database "test01" with owner="postgres" encoding='utf-8';(單引號,雙引號不能錯(cuò))

pg_dump -U postgres -f /postgres.sql -t test01 postgres(數(shù)據(jù)庫名)

4. 導(dǎo)出postgres數(shù)據(jù)庫中表test01的數(shù)據(jù),以insert語句的形式

pg_dump -U postgres -f /postgres.sql -t test01 --column-inserts postgres(數(shù)據(jù)庫名)

5. 恢復(fù)數(shù)據(jù)到bk01數(shù)據(jù)庫

psql -U postgres -f /postgres.sql bk01

二、 使用歸檔文件格式:

pg_restore

使用pg_restore純文本恢復(fù)純文本格式的腳本,無法恢復(fù)

[root@localhost postgres-9.3.5]# pg_restore -U postgres -d bk01 /mnt/hgfs/window&ubuntu\ shared\ folder/vendemo.sql

pg_restore: [archiver] input file appears to be a text format dump. Please use psql.

pg_restore和歸檔文件格式一起使用重建數(shù)據(jù)庫。

1. 先備份:

pg_dump -U postgres -F t -f /vendemo.tar vendemo 備份下來有800多k

. 恢復(fù):

pg_restore -U postgres -d bk01 /vendemo.tar

2. 先備份:

pg_dump -U postgres -F c -f /vendemo.tar vendemo 備份下來有300多k

. 恢復(fù):

pg_restore -U postgres -d bk01 /vendemo.tar

三、 壓縮備份與恢復(fù):

處理

大數(shù)據(jù)

庫:

1. 使用壓縮的轉(zhuǎn)儲. 使用你熟悉的壓縮程序,比如說 gzip。

. 先備份:

pg_dump -U postgres vendemo | gzip > /vendemo.gz 備份下來只有30多k

. 恢復(fù):

gunzip -c /vendemo.gz | psql -U postgres bk02

或者

cat /vendemo.gz | gunzip | psql -U postgres bk02

2. 使用 split。. split 命令允許你 你用下面的方法把輸出分解成

操作系統(tǒng)

可以接受的大小。 比如,讓每個(gè)塊大小為 1 兆字節(jié):

. 先備份:

pg_dump -U postgres -d vendemo | split -b 100k - /vend/vend

導(dǎo)出來的樣子是 vendaa 100k

vendab 100k

vendac 100k

vendad 16k

. 恢復(fù):

cat /vend/vend* | psql -U postgres bk02

夢里尋他千百度,伊人卻在燈火闌珊處...其實(shí)PostgreSQL內(nèi)置不少的工具,尋找的備份恢復(fù)方案就在其中:pg_dump,psql。這兩個(gè)指令 在數(shù)據(jù)庫的安裝目錄下,比如我自己本地安裝的,路徑形如:C:\Program Files\PostgreSQL\9.5\;然后進(jìn)入到bin文件夾,會(huì)看到不少的exe文件,這就是PostgreSQL內(nèi)置的工具了。里面會(huì)找到 pg_dump.exe,psql.exe兩個(gè)文件。我們怎么用他們?

用法:

備份數(shù)據(jù)庫

,指令如下:

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">pg_dump -h 164.82.233.54 -U postgres databasename > C:\databasename.bak</pre>

開始-運(yùn)行-cmd 彈出dos控制臺;然后 在控制臺里,進(jìn)入PostgreSQL安裝目錄bin下:

cd C:\Program Files\PostgreSQL\9.0\bin

最后執(zhí)行備份指令:

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">pg_dump -h 164.82.233.54 -U postgres databasename > C:\databasename.bak</pre>

指令解釋:如上命令,pg_dump 是備份數(shù)據(jù)庫指令,164.82.233.54是數(shù)據(jù)庫的ip地址(必須保證數(shù)據(jù)庫允許外部訪問的權(quán)限哦~),當(dāng)然本地的數(shù)據(jù)庫ip寫 localhost;postgres 是數(shù)據(jù)庫的用戶名;databasename 是數(shù)據(jù)庫名。> 意思是導(dǎo)出到C:\databasename.bak文件里,如果沒有寫路徑,單單寫databasename.bak文件名,那么備份文件會(huì)保存在C: \Program Files\PostgreSQL\9.0\bin 文件夾里。

恢復(fù)數(shù)據(jù)庫 ,指令如下:

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">**psql -h localhost -U postgres -d databasename < C:\databasename.bak(測試沒有成功)

pg_restore.exe --host localhost --port 5432 --username "postgres" --dbname "symbolmcnew" --no-password --verbose "databasename.backup"(測試成功)** </pre>

指令解釋:如上命令,psql是恢復(fù)數(shù)據(jù)庫命令,localhost是要恢復(fù)到哪個(gè)數(shù)據(jù)庫的地址,當(dāng)然你可以寫上ip地址,也就是說能遠(yuǎn)程恢復(fù)(必須保證 數(shù)據(jù)庫允許外部訪問的權(quán)限哦~);postgres 就是要恢復(fù)到哪個(gè)數(shù)據(jù)庫的用戶;databasename 是要恢復(fù)到哪個(gè)數(shù)據(jù)庫。< 的意思是把C:\databasename.bak文件導(dǎo)入到指定的數(shù)據(jù)庫里。

以上所有的是針對windows而言的,如果在linux下,會(huì)不會(huì)有效?

在linux里依然有效。有一個(gè)值得注意的是:如果直接進(jìn)入PostgreSQL的安裝目錄bin下,執(zhí)行命令,可能會(huì)出現(xiàn) 找不到pg_dump,psql?的現(xiàn)象,我們在可以這樣:

備份

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">/opt/PostgreSQL/9.5/bin/pg_dump -h 164.82.233.54 -U postgres databasename > databasename.bak</pre>

恢復(fù)

<pre class="sql" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">/opt/PostgreSQL/9.5/bin/psql -h localhost -U postgres -d databasename < databasename.bak</pre>

##########################MYSQL DUMP Restore###############################

mysqldump命令式備份整個(gè)DB用的。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">shell> mysqldump *db_name* > *backup-file.sql*
</pre>

把備份的數(shù)據(jù)導(dǎo)入空數(shù)據(jù)庫的命令。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">shell> mysql *db_name* < *backup-file.sql*
</pre>

或者下面的這個(gè)命令。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">shell> mysql -e "source */path-to-backup/backup-file.sql*" *db_name*</pre>

在使用上面的命令的時(shí)候有可能會(huì)報(bào)版本不對。

原因是Linux中mysql命令的版本和你想導(dǎo)入的那個(gè)數(shù)據(jù)庫的版本不一致。

變通做法是跑到數(shù)據(jù)庫的bin目錄下面。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">sshell> ./mysqldump *db_name* > *backup-file.sql*</pre>

把備份的數(shù)據(jù)導(dǎo)入空數(shù)據(jù)庫的命令。

<pre class="programlisting" style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">shell> ./mysql *db_name* < *backup-file.sql*</pre>

######################################################################
Git GitFlow SVN
http://svnbook.red-bean.com/

##############################SVN 規(guī)范標(biāo)準(zhǔn)###################################

Subversion有一個(gè)很標(biāo)準(zhǔn)的目錄結(jié)構(gòu),是這樣的。
比如項(xiàng)目是proj,svn地址為<a rel="nofollow" style="color: rgb(53, 114, 176); text-decoration: none;">svn://proj/,那么標(biāo)準(zhǔn)的svn布局是</a>

<pre style="margin: 10px 0px 0px; padding: 0px; font-family: ConfluenceInstalledFont, monospace; color: rgb(51, 51, 51); font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">svn://proj/
|
+-trunk
+-branches
+-tags</pre>

這是一個(gè)標(biāo)準(zhǔn)的布局,trunk為主開發(fā)目錄,branches為分支開發(fā)目錄,tags為tag存檔目錄(不允許修改)。但是具體這幾個(gè)目錄應(yīng)該如何使用,svn并沒有明確的規(guī)范,更多的還是用戶自己的習(xí)慣。

對于這幾個(gè)開發(fā)目錄,一般的使用方法有兩種。我更多的是從軟件產(chǎn)品的角度出發(fā)(比如freebsd),因?yàn)榛ヂ?lián)網(wǎng)的開發(fā)模式是完全不一樣的。

第一種方法,使用trunk作為主要的開發(fā)目錄。

一般的,我們的所有的開發(fā)都是基于trunk進(jìn)行開發(fā),當(dāng)一個(gè)版本/release開發(fā)告一段落(開發(fā)、測試、文檔、制作安裝程序、打包等)結(jié)束后,代碼處于凍結(jié)狀態(tài)(人為規(guī)定,可以通過hook來進(jìn)行管理)。此時(shí)應(yīng)該基于當(dāng)前凍結(jié)的代碼庫,打tag。當(dāng)下一個(gè)版本/階段的開發(fā)任務(wù)開始,繼續(xù)在trunk進(jìn)行開發(fā)。

此時(shí),如果發(fā)現(xiàn)了上一個(gè)已發(fā)行版本(Released Version)有一些bug,或者一些很急迫的功能要求,而正在開發(fā)的版本(Developing Version)無法滿足時(shí)間要求,這時(shí)候就需要在上一個(gè)版本上進(jìn)行修改了。應(yīng)該基于發(fā)行版對應(yīng)的tag,做相應(yīng)的分支(branch)進(jìn)行開發(fā)。

例如,剛剛發(fā)布1.0,正在開發(fā)2.0,此時(shí)要在1.0的基礎(chǔ)上進(jìn)行bug修正。

按照時(shí)間的順序

  1. 1.0開發(fā)完畢,代碼凍結(jié)
  2. 基于已經(jīng)凍結(jié)的trunk,為release1.0打tag
    此時(shí)的目錄結(jié)構(gòu)為
    svn://proj/
    +trunk/ (freeze)
    +branches/
    +tags/
    +tag_release_1.0 (copy from trunk)
  3. 2.0開始開發(fā),trunk此時(shí)為2.0的開發(fā)版
  4. 發(fā)現(xiàn)1.0有bug,需要修改,基于1.0的tag做branch
    此時(shí)的目錄結(jié)構(gòu)為
    svn://proj/
    +trunk/ ( dev 2.0 )
    +branches/
    +dev_1.0_bugfix (copy from tag/release_1.0)
    +tags/
    +release_1.0 (copy from trunk)
  5. 在1.0 bugfix branch進(jìn)行1.0 bugfix開發(fā),在trunk進(jìn)行2.0開發(fā)
  6. 在1.0 bugfix 完成之后,基于dev_1.0_bugfix的branch做release等
  7. 根據(jù)需要選擇性的把dev_1.0_bugfix這個(gè)分支merge回trunk(什么時(shí)候進(jìn)行這步操作,要根據(jù)具體情況)

這是一種很標(biāo)準(zhǔn)的開發(fā)模式,很多的公司都是采用這種模式進(jìn)行開發(fā)的。trunk永遠(yuǎn)是開發(fā)的主要目錄。

第二種方法,在每一個(gè)release的branch中進(jìn)行各自的開發(fā),trunk只做發(fā)布使用。
這種開發(fā)模式當(dāng)中,trunk是不承擔(dān)具體開發(fā)任務(wù)的,一個(gè)版本/階段的開發(fā)任務(wù)在開始的時(shí)候,根據(jù)已經(jīng)release的版本做新的開發(fā)分支,并且基于這個(gè)分支進(jìn)行開發(fā)。還是舉上面的例子,這里面的時(shí)序關(guān)系是。

  1. 1.0開發(fā),做dev1.0的branch
    此時(shí)的目錄結(jié)構(gòu)
    svn://proj/
    +trunk/ (不擔(dān)負(fù)開發(fā)任務(wù) )
    +branches/
    +dev_1.0 (copy from trunk)
    +tags/
  2. 1.0開發(fā)完成,merge dev1.0到trunk
    此時(shí)的目錄結(jié)構(gòu)
    svn://proj/
    +trunk/ (merge from branch dev_1.0)
    +branches/
    +dev_1.0 (開發(fā)任務(wù)結(jié)束,freeze)
    +tags/
  3. 根據(jù)trunk做1.0的tag
    此時(shí)的目錄結(jié)構(gòu)
    svn://proj/
    +trunk/ (merge from branch dev_1.0)
    +branches/
    +dev_1.0 (開發(fā)任務(wù)結(jié)束,freeze)
    +tags/
    +tag_release_1.0 (copy from trunk)
  4. 1.0開發(fā),做dev2.0分支
    此時(shí)的目錄結(jié)構(gòu)
    svn://proj/
    +trunk/
    +branches/
    +dev_1.0 (開發(fā)任務(wù)結(jié)束,freeze)
    +dev_2.0 (進(jìn)行2.0開發(fā))
    +tags/
    +tag_release_1.0 (copy from trunk)
  5. 1.0有bug,直接在dev1.0的分支上修復(fù)
    此時(shí)的目錄結(jié)構(gòu)
    svn://proj/
    +trunk/
    +branches/
    +dev_1.0 (1.0bugfix)
    +dev_2.0 (進(jìn)行2.0開發(fā))
    +tags/
    +tag_release_1.0 (copy from trunk)
  6. 選擇性的進(jìn)行代碼merge

這其實(shí)是一種分散式的開發(fā),當(dāng)各個(gè)部分相對獨(dú)立一些(功能性的),可以開多個(gè)dev的分支進(jìn)行開發(fā),這樣各人/組都不會(huì)相互影響。比如dev_2.0_search和dev_2.0_cache等。但是這樣merge起來就是一個(gè)很痛苦的事情。
這里要注意一下的,第六步進(jìn)行選擇性的merge,是可以當(dāng)2.0開發(fā)結(jié)束后一起把dev_1.0(bugfix用)和dev_2.0(新版本開發(fā)用)merge回trunk。或者先把dev_1.0 merge到dev_2.0,進(jìn)行測試等之后再merge回trunk。
這兩種方法各有利弊,第一種方法是可以得到一個(gè)比較純的dev_2.0的開發(fā)分支,而第二種方法則更加的保險(xiǎn),因?yàn)橐獪y試嘛。
以上呢,就是我說的兩種開發(fā)模式了,具體哪種好,并沒有定論。這里大致的說一下各自的優(yōu)缺點(diǎn)
第一種開發(fā)模式(trunk進(jìn)行主要開發(fā),集中式):
優(yōu)點(diǎn):管理簡單
缺點(diǎn):當(dāng)開發(fā)的模塊比較多,開發(fā)人數(shù)/小團(tuán)隊(duì)比較多的時(shí)候,很容易產(chǎn)生沖突而影響對方的開發(fā)。因?yàn)樗械母膭?dòng)都有可能觸碰對方的改動(dòng)
第二種開發(fā)模式(分支進(jìn)行主要開發(fā),分散式):
優(yōu)點(diǎn):各自開發(fā)獨(dú)立,不容易相互影響。
缺點(diǎn):管理復(fù)雜,merge的時(shí)候很麻煩,容易死人

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容