چند وقت پیشتر ها یه مشکلی پیدا کرده بودم با IBSng که مجبور شدم از دیتابیس ان بک آپ بگیرم مطالبی که در ان موقع یادگرفتم را در اینجا برای دوستان می اورم (در صورتی که به دردمی خوره مقاله اونو برای قرار دادن روی سایت بفرستم)
توضیح اینکه در صورتی که از روش اسکریپت نسخه پشتیبان را گرفتید باید با اسکریپت باز خوانی کنید. به صورتی که ابتدا نام اسکریپ restore را در خط فرمان می نویسید سپس با یک فاصله نام فایل خروجی از اسکریپت بک آپ
و در صورتی که باروش دستی این کار را کردید به روش دستی آن را برگردانید
Backup
1. Backup with ""pg_dump"" command (Best method)
$pg_dump -U {user-name} {source_db} -f {dumpfilename.sql}
For example :
pg_dump –U ibs ibs –f /home/backup/pgbackup.sql
2. Backup with script and out format (c,t,p)
#!/bin/sh
DATABASE=ibs
PGUSER=ibs
BACKUPDIR=/root
echo "Backup database $DATABASE."
bufilename=$BACKUPDIR/backup_`date '+%Y%m%d'`.gz
pg_dump --file=$bufilename --format=t --username=$PGUSER --password $DATABASE
echo "Done."
Restore
1- Restore with ""psql"" command (best method)
Step 1: Stop ibs Service
service ibs stop
Step 2: Set Password for postgres user
passwd postgres
Step 3: Remove old DB
dropdb -U postgres -W -i ibs
""-U or --username=USERNAME""
"" -W or --password""
""-i or --interactive""
Step 4: login to postgres
su - postgres
Step 5: Create DB ibs
createdb ibs
Step 6: Restore DB with psql
psql -U {user-name} -d {desintation_db}-f {dumpfilename.sql}
Method 1:
psql –U ibs –d ibs –f /home/backup/pgbackup.sql
Method 2: (Best method)
$exit
Psql –U ibs ibs
$\i /home/backup/pgbackup.sql
2- Restore with script
#!/bin/sh
DATABASE=ibs
PGUSER=ibs
PGPASSWORD=??????
if [ $# -ne 1 ] || [ ! -f $1 ]
then
echo "Usage: $0 <backupfile>"
exit 1
fi
bufilename=$1
echo "Dropping database $DATABASE"
dropdb -U $PGUSER $DATABASE
echo "Creating database $DATABASE"
createdb -U $PGUSER $DATABASE
echo "Restoring database $DATABASE from $bufilename"
pg_restore --verbose --username=$PGUSER --dbname=$DATABASE --format=t $bufilename
echo "Done!"