DataBase/MS-SQL

[MS-SQL] BCP 명령어로 백업과 복구하기

이지랩(ezLab) 2023. 1. 2. 12:17
반응형

 

 

[MS-SQL] BCP 명령어로 백업과 복구하기

 

 

백업 - 테이블 전체 백업받기

 

[사용방법]

bcp [DB명].dbo.[테이블명] out 파일명 -c -U[사용자ID] -P[패스워드]

 

[예]

bcp L2022.dbo.logtbl out d:\L2022.txt -c -Utest -P1234

 

백업 - 쿼리로 백업받기

 

[사용방법]

bcp "[쿼리]" queryout 파일명 -c -U[사용자ID] -P[패스워드]

 

[예 #1]

bcp "select num, ip, port from L2022.dbo.logtbl where idx_no <= 10" queryout "d:\L2022.txt" -c -Utest -P1234

 

[예 #2]

bcp
"select * from L2022.dbo.logtbl1 where idx_no <= 5 union all
 select * from L2022.dbo.logtbl2 where idx_no <= 5 union all
 select * from L2022.dbo.logtbl3 where idx_no <= 5"
queryout "d:\L2022.txt" -c -Utest -P1234

 


 

복구 (테이블이 생성되어있어야 한다)

 

[사용방법]

bcp [DB명].dbo.[테이블명] in 파일명 -c -U[사용자ID] -P[패스워드]


[예]

bcp L2022.dbo.logtbl in d:\L2022.txt -c -Utest -P1234

 

 

반응형