<<編程基礎-語言SQL.Git.Docker>>

<<編程基礎-語言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/
概述: 主要存放新產品研發的架構部署,架構解決方案,持續集成,持續部署和自動化的一些資料等。
############################################################################
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* 不管改不改房含 只要改了房價 noshow 預定未到 結賬folio 就是結賬賬單-已結賬下面 下個+下面的
001.房價=====================================================
每日房價記錄數與住店時間一致
houseblock記錄數與住店時間一致
每日收取的房含要出現在每日房含表中的每一天,首日房含只能出現在首日
一期所有每日房價的價格代碼、折扣一樣
RT+只能有一套房含
RT只能有一套房含,且每日價格設定一樣
002.預訂=====================================================
沒有來期大于等于今日的noshow賬戶
沒有離期小于今日的在店賬戶
沒有來期小于今日的預訂賬戶
沒有來期大于今日的在店賬戶
每個賬戶至少有一個住店客人,且賬戶表里的住店客人ID對應的存在
每個賬戶只能有一個預訂人,且賬戶表里的預訂人ID對應的存在
003.賬務====================================================
客賬交易金額與賬務明細金額一致,12個細項金額也一致
賬單的余額為0
已結賬戶余額為0
結賬folio里的幾個金額與明細一致
轉賬folio里的幾個金額與明細一致
004.客房====================================================
空房態沒有在店賬戶
占用房態必有在店賬戶
維修房態有對應的維修記錄
houseblock
###################################################################
白盒測試 by 20170622
房價 housingprice_test001 housingprice_test002 housingprice_test003
1.每日房價記錄數與住店時間一致
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記錄數與住店時間一致
select * from emp where empno=7369 for update;
3.每日收取的房含要出現在每日房含表中的每一天,首日房含只能出現在首日
select * from emp where empno=7369 for update;
4.一期所有每日房價的價格代碼、折扣一樣
select * from emp where empno=7369 for update;
5.RT+只能有一套房含
select * from emp where empno=7369 for update;
6.RT
只能有一套房含,且每日價格設定一樣
select * from emp where empno=7369 for update;
7.每日房含12個分項的合計與每日房價的一致
select * from emp where empno=7369 for update;

預訂 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.沒有來期小于今日的預訂賬戶
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.每個賬戶至少有一個住店客人,且賬戶表里的住店客人ID對應的存在

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.每個賬戶只能有一個預訂人,且賬戶表里的預訂人ID對應的存在

(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)

賬務 financial_test001 financial_test002

1.客賬交易金額與賬務明細金額一致,12個細項金額也一致
金額一致:
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
細項一致:
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.已結賬戶余額為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.結賬folio里的幾個金額與明細一致
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.轉賬folio里的幾個金額與明細一致
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.空房態沒有在店賬戶
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.占用房態必有在店賬戶
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.維修房態有對應的維修記錄
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<=當日 AND end_dt>=當日)
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自帶一個客戶端pgAdmin,里面有個備份,恢復選項,也能對數據庫進行備份 恢復(還原),但最近發現數據庫慢慢龐大的時候,經常出錯,備份的文件過程中出錯的幾率那是相當大,手動調節灰常有限。所以一直尋找完美的備份恢復方案。

一: 純文件格式的腳本:

示例:

1. 只導出postgres數據庫的數據,不包括模式 -s

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

2. 導出postgres數據庫(包括數據)

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

3. 導出postgres數據庫中表test01的數據

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

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

4. 導出postgres數據庫中表test01的數據,以insert語句的形式

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

5. 恢復數據到bk01數據庫

psql -U postgres -f /postgres.sql bk01

二、 使用歸檔文件格式:

pg_restore

使用pg_restore純文本恢復純文本格式的腳本,無法恢復

[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和歸檔文件格式一起使用重建數據庫。

1. 先備份:

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

. 恢復:

pg_restore -U postgres -d bk01 /vendemo.tar

2. 先備份:

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

. 恢復:

pg_restore -U postgres -d bk01 /vendemo.tar

三、 壓縮備份與恢復:

處理

大數據

庫:

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

. 先備份:

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

. 恢復:

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

或者

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

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

操作系統

可以接受的大小。 比如,讓每個塊大小為 1 兆字節:

. 先備份:

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

導出來的樣子是 vendaa 100k

vendab 100k

vendac 100k

vendad 16k

. 恢復:

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

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

用法:

備份數據庫

,指令如下:

<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>

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

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

最后執行備份指令:

<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 是備份數據庫指令,164.82.233.54是數據庫的ip地址(必須保證數據庫允許外部訪問的權限哦~),當然本地的數據庫ip寫 localhost;postgres 是數據庫的用戶名;databasename 是數據庫名。> 意思是導出到C:\databasename.bak文件里,如果沒有寫路徑,單單寫databasename.bak文件名,那么備份文件會保存在C: \Program Files\PostgreSQL\9.0\bin 文件夾里。

恢復數據庫 ,指令如下:

<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是恢復數據庫命令,localhost是要恢復到哪個數據庫的地址,當然你可以寫上ip地址,也就是說能遠程恢復(必須保證 數據庫允許外部訪問的權限哦~);postgres 就是要恢復到哪個數據庫的用戶;databasename 是要恢復到哪個數據庫。< 的意思是把C:\databasename.bak文件導入到指定的數據庫里。

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

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

備份

<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>

恢復

<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命令式備份整個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>

把備份的數據導入空數據庫的命令。

<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>

或者下面的這個命令。

<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>

在使用上面的命令的時候有可能會報版本不對。

原因是Linux中mysql命令的版本和你想導入的那個數據庫的版本不一致。

變通做法是跑到數據庫的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>

把備份的數據導入空數據庫的命令。

<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自帶一個客戶端pgAdmin,里面有個備份,恢復選項,也能對數據庫進行備份 恢復(還原),但最近發現數據庫慢慢龐大的時候,經常出錯,備份的文件過程中出錯的幾率那是相當大,手動調節灰常有限。所以一直尋找完美的備份恢復方案。

一: 純文件格式的腳本:

示例:

1. 只導出postgres數據庫的數據,不包括模式 -s

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

2. 導出postgres數據庫(包括數據)

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

3. 導出postgres數據庫中表test01的數據

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

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

4. 導出postgres數據庫中表test01的數據,以insert語句的形式

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

5. 恢復數據到bk01數據庫

psql -U postgres -f /postgres.sql bk01

二、 使用歸檔文件格式:

pg_restore

使用pg_restore純文本恢復純文本格式的腳本,無法恢復

[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和歸檔文件格式一起使用重建數據庫。

1. 先備份:

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

. 恢復:

pg_restore -U postgres -d bk01 /vendemo.tar

2. 先備份:

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

. 恢復:

pg_restore -U postgres -d bk01 /vendemo.tar

三、 壓縮備份與恢復:

處理

大數據

庫:

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

. 先備份:

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

. 恢復:

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

或者

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

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

操作系統

可以接受的大小。 比如,讓每個塊大小為 1 兆字節:

. 先備份:

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

導出來的樣子是 vendaa 100k

vendab 100k

vendac 100k

vendad 16k

. 恢復:

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

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

用法:

備份數據庫

,指令如下:

<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>

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

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

最后執行備份指令:

<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 是備份數據庫指令,164.82.233.54是數據庫的ip地址(必須保證數據庫允許外部訪問的權限哦~),當然本地的數據庫ip寫 localhost;postgres 是數據庫的用戶名;databasename 是數據庫名。> 意思是導出到C:\databasename.bak文件里,如果沒有寫路徑,單單寫databasename.bak文件名,那么備份文件會保存在C: \Program Files\PostgreSQL\9.0\bin 文件夾里。

恢復數據庫 ,指令如下:

<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是恢復數據庫命令,localhost是要恢復到哪個數據庫的地址,當然你可以寫上ip地址,也就是說能遠程恢復(必須保證 數據庫允許外部訪問的權限哦~);postgres 就是要恢復到哪個數據庫的用戶;databasename 是要恢復到哪個數據庫。< 的意思是把C:\databasename.bak文件導入到指定的數據庫里。

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

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

備份

<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>

恢復

<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命令式備份整個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>

把備份的數據導入空數據庫的命令。

<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>

或者下面的這個命令。

<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>

在使用上面的命令的時候有可能會報版本不對。

原因是Linux中mysql命令的版本和你想導入的那個數據庫的版本不一致。

變通做法是跑到數據庫的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>

把備份的數據導入空數據庫的命令。

<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 規范標準###################################

Subversion有一個很標準的目錄結構,是這樣的。
比如項目是proj,svn地址為<a rel="nofollow" style="color: rgb(53, 114, 176); text-decoration: none;">svn://proj/,那么標準的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>

這是一個標準的布局,trunk為主開發目錄,branches為分支開發目錄,tags為tag存檔目錄(不允許修改)。但是具體這幾個目錄應該如何使用,svn并沒有明確的規范,更多的還是用戶自己的習慣。

對于這幾個開發目錄,一般的使用方法有兩種。我更多的是從軟件產品的角度出發(比如freebsd),因為互聯網的開發模式是完全不一樣的。

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

一般的,我們的所有的開發都是基于trunk進行開發,當一個版本/release開發告一段落(開發、測試、文檔、制作安裝程序、打包等)結束后,代碼處于凍結狀態(人為規定,可以通過hook來進行管理)。此時應該基于當前凍結的代碼庫,打tag。當下一個版本/階段的開發任務開始,繼續在trunk進行開發。

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

例如,剛剛發布1.0,正在開發2.0,此時要在1.0的基礎上進行bug修正。

按照時間的順序

  1. 1.0開發完畢,代碼凍結
  2. 基于已經凍結的trunk,為release1.0打tag
    此時的目錄結構為
    svn://proj/
    +trunk/ (freeze)
    +branches/
    +tags/
    +tag_release_1.0 (copy from trunk)
  3. 2.0開始開發,trunk此時為2.0的開發版
  4. 發現1.0有bug,需要修改,基于1.0的tag做branch
    此時的目錄結構為
    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進行1.0 bugfix開發,在trunk進行2.0開發
  6. 在1.0 bugfix 完成之后,基于dev_1.0_bugfix的branch做release等
  7. 根據需要選擇性的把dev_1.0_bugfix這個分支merge回trunk(什么時候進行這步操作,要根據具體情況)

這是一種很標準的開發模式,很多的公司都是采用這種模式進行開發的。trunk永遠是開發的主要目錄。

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

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

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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容