PostgreSQL Backup And Restore
-Requirements & Installation:-
Source:
1. http://php.net/manual/en/book.com.php
2. http://php.net/manual/en/com.installation.php
From PHP 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini:
[COM_DOT_NET]
extension=php_com_dotnet.dll
batch_file_backup.bat
@echo off
SET PGPATH="E:\PostgreSQL\9.5\bin\pg_dump.exe"
SET PGPASSWORD=admin
%PGPATH% -h 127.0.0.1 -p 5432 -U postgres -F c -b -v -f C:\Users\Pukar\Downloads\backupfile\2017-04-04.backup qkbase_db_local
backup.php
$batchfile_path = "E:/xampp/htdocs/yig2016/ybase/main_app/bizlayer/protected/batch_file_backup.bat";
$WshShell = new COM("WScript.Shell");
$exec = $WshShell->Run($batchfile_path, 0, false);
batch_file_restore.bat
@echo off
SET PGPATH="E:\PostgreSQL\9.5\bin\pg_restore.exe"
SET PGPASSWORD=admin
%PGPATH% -h 127.0.0.1 -p 5432 -U postgres -d qkbase_db -v C:\Users\Pukar\Downloads\backupfile\2017-04-04.backup
restore.php
$batchfile_path = "E:/xampp/htdocs/yig2016/ybase/main_app/bizlayer/protected/batch_file_restore.bat";
$WshShell = new COM("WScript.Shell");
$exec = $WshShell->Run($batchfile_path, 0, false);
Using PHP Script:-
Backup:
putenv('PGPASSWORD=admin'); $result = 'E:\PostgreSQL\9.5\bin\pg_dump.exe -h 127.0.0.1 -p 5432 -U postgres -F c -b -v -f C:\Users\Pukar\Downloads\backupfile\2017-04-04.backup qkbase_db_local'; $WshShell = new COM("WScript.Shell"); $exec = $WshShell->Run($result, 0, false);
Restore:
putenv('PGPASSWORD=admin');
$result = 'E:\PostgreSQL\9.5\bin\pg_restore.exe -h 127.0.0.1 -p 5432 -U postgres -d qkbase_db -v C:\Users\Pukar\Downloads\backupfile\2017-04-04.backup';
$WshShell = new COM("WScript.Shell");
$exec = $WshShell->Run($result, 0, false);
0 comments:
Post a Comment