내용으로 건너뛰기
GaramX
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
현재 위치:
home
»
postgresql
»
backup_and_restore
추적:
postgresql:backup_and_restore
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== Backup And Restore ====== ===== Backup ===== <code bash backup.sh> #DB 정보설정 dbname=postgre port=5432 username=postgre if [ "" != "$1" ]; then file_name=$1 else host_name=db.xxxx.com file_name=db_xxxx_backup.gz fi read -p "백업하려는서버($host_name): " name if [ -n "$name" ]; then host_name="$name" fi startDate=$(date) echo "================================" echo "== 장고-데이터를 백업시작합니다." echo "== 서버 : $host_name" echo "== start time : ${startDate}" echo "================================" <<comment Postgresql의 pg_dump를 이용한 백업을 실시합니다. comment pg_dump --dbname=${dbname} --host=${host_name} --port=${port} --username=${username} --clean | gzip > ${file_name} if [ $? -eq 0 ]; then endDate=$(date) echo "=========== 백업성공============" echo "== 서버명 : ${host_name}" echo "== 파일명 : ${file_name}" echo "== end time : ${endDate}" echo "================================" else echo "================================" echo "Failure!" echo "================================" fi </code> ===== Restore ===== <code bash restore.sh> # DB 정보설정 dbname=dbname port=5432 username=postgresql if [ "" != "$1" ]; then file_name=$1 else host_name=db.xxxx.com file_name=db_xxxx_backup.gz fi read -p "대상서버: " name if [ -n "$name" ]; then host_name="$name" fi echo "================================" echo "== 장고-데이터를 복원합니다. ==" echo "== 서버 : $host_name" echo "== 백업파일명 : $file_name" echo "================================" <<comment PostgreSQL을 복원합니다. comment gunzip -c ${file_name} | psql --dbname={dbname} --host=${host_name} --port=${port} --username=${username} if [ $? -eq 0 ]; then echo "================================" echo "== 서버명 - ${host_name} ==" echo "== 복원성공- ${file_name} ==" echo "================================" else echo "================================" echo "Failure!" echo "================================" fi </code> ===== 테이블 날리기 ===== <code sql> ---SELECT tablename FROM pg_tables WHERE schemaname = current_schema() DO $$ DECLARE r RECORD; BEGIN -- if the schema you operate on is not "current", you will want to -- replace current_schema() in query with 'schematodeletetablesfrom' -- *and* update the generate 'DROP...' accordingly. FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE'; END LOOP; END $$; ---SELECT tablename FROM pg_tables WHERE schemaname = current_schema() </code> ===== 삭제 ===== <code sql> DO $$ DECLARE r RECORD; BEGIN -- if the schema you operate on is not "current", you will want to -- replace current_schema() in query with 'schematodeletetablesfrom' -- *and* update the generate 'DROP...' accordingly. FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP EXECUTE 'DELETE FROM ' || quote_ident(r.tablename) ; END LOOP; END $$; </code>
postgresql/backup_and_restore.txt
· 마지막으로 수정됨: 2025/04/15 10:05 저자
127.0.0.1
문서 도구
문서 보기
이전 판
역링크
맨 위로