Doing a backup of repository solution

Is is possible to script a daily backup of a solution inside the repository?

Or possibly is some other way export a solution to a file?

yes: see repository (under file-menu) export solution! :-)

If you run iAnywhere you can also have the db do the backups. Connect to it using SQL and run this:

CREATE EVENT NightlyBackup
SCHEDULE 
START TIME '23:00' EVERY 24 HOURS
HANDLER
BEGIN
    DECLARE cmd LONG VARCHAR;
    DECLARE day_name CHAR(20);
    
    SET day_name = DATENAME(WEEKDAY, CURRENT DATE);
    SET cmd = 'BACKUP DATABASE DIRECTORY ' ||
      '''d:\\backups\\' || day_name || ''' ' ||
      'TRANSACTION LOG RENAME';
    EXECUTE IMMEDIATE WITH ESCAPES OFF cmd;
END

Repeat the above for each database you wish to backup. Make sure to adjust your path in the code above!

I don’t understand. I know I can do it manually in: file->Resopsitory ->Export to File.

My question is: Is there a way to set up a scheduled method that will export the solution to a file automatically?

elyod_72:
I don’t understand. I know I can do it manually in: file->Resopsitory ->Export to File.

My question is: Is there a way to set up a scheduled method that will export the solution to a file automatically?

See my method above.

This is my backup method, it triggers a Stored Procedure in Sybase (see Jan post), it’s quite complex but it should give you an idea.

// Ask for the destination directory
var confirm = plugins.dialogs.showWarningDialog('DB Backup','The Backup can take several minutes, proceed with the Backup?','Cancel','Ok')
if ( confirm == 'Cancel')
{
	return;
}
plugins.dialogs.showInfoDialog('DB Backup','Select the directory where you want to save your Backup.','Ok')
var backup_dir = plugins.file.showDirectorySelectDialog();

// Usciamo se l'utente ha cancellato l'operazione
if (!backup_dir)
{
	return;
}

// Create the new record
controller.newRecord(true)
database_file = globals.sintpro_backup_current_db_file
database_log_file = globals.sintpro_backup_current_log_file
db_file_size = globals.sintpro_backup_db_size
db_log_size = globals.sintpro_backup_log_size

// We reorder the list
controller.sort('backup_timestamp desc')

// We create a subdir in the destination dir
backup_dir = backup_dir + '/Backup_' + backupsid
backup_path = plugins.file.convertStringToJSFile(backup_dir)

// Execute the Stored Procedure called 'backup'
// We use an ALTER stament on the procedure so if it doesn't exists
// is created on the fly

var iArray = new Array(2); 
var argArray = new Array(2); 

// SP output parameter
iArray[0] = 1
argArray[0] = java.sql.Types.INTEGER
// SP input parameter
iArray[1] = 0 
argArray[1] = backup_dir

// Let's start a progress bar to give the user some feedback
// Too bad the progress bar doesn't update... :(

forms.sintpro_backup_main.elements.progress_bar.visible = true
forms.sintpro_backup_main.elements.progress_bar.orientation = 0 
forms.sintpro_backup_main.elements.progress_bar.stringPainted = true
forms.sintpro_backup_main.elements.progress_bar.string = "Performing Backup..."
forms.sintpro_backup_main.elements.progress_bar.value =0 
forms.sintpro_backup_main.elements.progress_bar.minimum = 0
forms.sintpro_backup_main.elements.progress_bar.maximum = 100
forms.sintpro_backup_main.elements.progress_bar.indeterminate
application.updateUI()

var result = databaseManager.executeStoredProcedure(currentcontroller.getServerName(),'{?=call "dba"."backup"(?)}',argArray,iArray,0)
application.beep()

// Check if the backup is been performed otherwise show the Exception
var error = result.getExceptionMsg()

if ( error )
{
	plugins.dialogs.showErrorDialog('DB Backup',error + '\nBackup not saved!','Ok')
	backup_path = 'Error:\n' + error
}
else
{
	// Recalculate the LOG size
	globals.sintpro_backup_log_size = plugins.file.getFileSize(globals.sintpro_backup_current_log_file)
	
	// Let's ask if they want to zip the backup file
	zip = plugins.dialogs.showQuestionDialog('DB Backup','Backup saved succesfully to '+ backup_dir +
	'\nDo you want to compress the Backup with Zip?','No','Yes')
	
	if ( zip == 'Yes' )
	{
		forms.sintpro_backup_main.elements.progress_bar.string = "Compressing Backup..."
		application.updateUI()
		var zipdir = plugins.file.convertStringToJSFile(backup_dir)
		var zipfile = plugins.it2be_tools.zip(zipdir.getAbsolutePath())
		if ( zipfile )
		{
			var del = plugins.file.deleteFolder(zipdir.getAbsolutePath(),false)
		}
	}
	
	// We finish
	application.beep()
	plugins.dialogs.showInfoDialog('DB Backup','Backup complete','Ok')

}

// Reset the progress bar
forms.sintpro_backup_main.elements.progress_bar.string = ""
application.updateUI()

On Windows using Sybase I create automated backups using a bat file for each day of the week. For example, for Monday I use:

cd C:\PROGRA~1\SERVOY\sybase~1\win32\
C:\PROGRA~1\SERVOY\sybase~1\win32\dbbackup.exe -y -c "uid=dba;pwd=sql;dbn=contacts" C:\PROGRA~1\SERVOY\backups\monday
C:\PROGRA~1\SERVOY\sybase~1\win32\dbbackup.exe -y -c "uid=dba;pwd=sql;dbn=holders" C:\PROGRA~1\SERVOY\backups\monday
C:\PROGRA~1\SERVOY\sybase~1\win32\dbbackup.exe -y -c "uid=dba;pwd=sql;dbn=log_data" C:\PROGRA~1\SERVOY\backups\monday
C:\PROGRA~1\SERVOY\sybase~1\win32\dbbackup.exe -y -c "uid=dba;pwd=sql;dbn=pdf_forms" C:\PROGRA~1\SERVOY\backups\monday
C:\PROGRA~1\SERVOY\sybase~1\win32\dbbackup.exe -y -c "uid=dba;pwd=sql;dbn=servoy_repository" C:\PROGRA~1\SERVOY\backups\monday
C:\PROGRA~1\SERVOY\sybase~1\win32\dbbackup.exe -y -c "uid=dba;pwd=sql;dbn=updates" C:\PROGRA~1\SERVOY\backups\monday
copy "C:\PROGRA~1\SERVOY\servoy.properties" C:\PROGRA~1\SERVOY\backups\monday

(Note: The code shown above is eight lines)

The above pauses each database, copies it and then resumes the database. It also makes a copy of the servoy.properties file.

uid = username and pwd = password.

Be careful using the shortnames. I seem to recall having a problem in the past when there were two folders with names that started with the same six characters.

So for Monday the about is saved as a text file that ends with the .bat extension. Then I use the built-in Windows “Scheduled Tasks” wizard under Start/All Programs/Accessories/System Tools/Scheduled Tasks to execute the appropriate bat file for each day.

To make the above work, I place the following Sybase Central files in a “win32” folder at Seryoy/sybase_db/win32:

dbbackup.exe 100kb
dblgen9.dll 572kb
dblib9.dll 440kb
dbsvc.exe 112kb
dbtool9.dll 1,052kb

Dean

Since elyod_72 didn’t mention what database engine he uses for the servoy repository… ;)

If you have your servoy repository in PostgreSQL then you simply use pg_dump or pg_dumpall to backup the database. It’s VERY fast.

pg_dumpall -U username > /path/to/allMyData.backup

To restore the data you use pg_restore.
You can create a script you put in a crontab or some scheduler or you can do it manually with the commandline or with the pgAdmin III application.

Hope this helps.

Hi elyod_72,

Reading your second question again I see you actually wanted to automate the exporting of the solution (for backup purposes).

Short answer: you can’t.

You can only do this manually.
The only solution is to backup the whole database as specified in previous replies.

I am using MySQL.
I see from the other posts that I can do a backup of the database, and that is what I will do.

And yes you are correct, the origional question was the ability to do the export backup from inside Servoy.
Thank you for your answer.

elyod_72:
I am using MySQL.
I see from the other posts that I can do a backup of the database, and that is what I will do.

You can create a backup script on the server and trigger it using a small solution invoked by an headless client session.
Quick guidelines:

  • Create a backup script that uses mysqldump to backup the selected database and store it on the server;
  • Create a small solution with a method that triggers the backup script using the function “application.executeProgramInBackground()”;
  • Create a javascript page that invokes the above method in an headless client session;
  • Open the javascript url from your solution to start the backup.

You can even pass parameters so you can build a standard backup system and pass the options (database name, structure only or data & structure, etc.) to the shell script.

Hope you get the picture.

Hi Westy,

I used your technique to backup my repository db and it just works perfect.

Thanks for sharing!

Hi there,

I want to know how can I rename the sysbase transaction log file.
I tried with the sybase central and it doesn’t seem to provide an option for that. Could you please help me out?

Thanks a lot!

ngervasi:
You can create a backup script on the server and trigger it using a small solution invoked by an headless client session.
Quick guidelines:

  • Create a backup script that uses mysqldump to backup the selected database and store it on the server;
  • Create a small solution with a method that triggers the backup script using the function “application.executeProgramInBackground()”;
  • Create a javascript page that invokes the above method in an headless client session;
  • Open the javascript url from your solution to start the backup.

You can even pass parameters so you can build a standard backup system and pass the options (database name, structure only or data & structure, etc.) to the shell script.

Hope you get the picture.

Hi! I am also trying this approach but using postgresql. What if the user wants a local copy of the dump? Could you help me if this is feasible?

thanks!