At the moment, the server is working on Windows. But this method have to work with Linux and Mac OS/X.
In first, I wanted to create a stored procedure in PostgreSQL and executed it from servoy. But Postres don’t allow to create Procedure, only function. Unfortunately I can’t execute a REINDEX, PG_DUMP OR VACUUM command on database in function because “REINDEX cannot be executed inside a transaction block.”
http://www.postgresql.org/docs/8.2/inte … index.html
So I choosed to use cronjob. I created a Startup script :
var jobname = “backup”
var cronTimings = “* 00 22 * * ?”
var startDate = new Date()
var endDate = new Date(startDate.getFullYear()+50,startDate.getMonth(),startDate.getDate())
var args = new Array(directory_postgres,directory_for_backup)plugins.scheduler.addCronJob(jobname, cronTimings, globals.Backup_DB,startDate,endDate,args)
The method backup:
var directory_postgres = arguments[0]
var directory_for_backup= arguments[1]//Returns the name of the operating system
var osname = application.getOSName();if(osname.indexOf(“Windows”,0)>-1){
var file = plugins.file.convertToJSFile(directory_postgres +“/vacuumdb.exe”)
if(file.exists())
application.executeProgram(directory_postgres +“/vacuumdb.exe”,“-h”,“localhost”,“-p”,“5432”,“-U”,“postgres”,“-d”,“sopavet”)var file = plugins.file.convertToJSFile(directory_postgres +“/reindexdb.exe”)
if(file.exists())
application.executeProgram(directory_postgres +“/reindexdb.exe”,“-h”,“localhost”,“-p”,“5432”,“-U”,“postgres”,“-d”,“sopavet”var file = plugins.file.convertToJSFile(directory_postgres +“/pg_dump.exe”)
if(file.exists())
application.executeProgram(directory_postgres +“/pg_dump.exe”,“-i”,“-h”,“localhost”,“-p”,“5432”,“-U”,“postgres”,“-F”,“t”,“-f”,“"“directory_for_backup+”/database_save.backup"”,“sopavet”}
I have to add security rules with postgres’s user and complete this method for Linux and Mac OS/X.
It’s work fine on Windows XP with Postgres 8.1, but I didn’t know that batch process use one client license .So I have to find another way to backup my database.