Doing a backup of repository solution

Questions, tips and tricks and techniques for scripting in Servoy

Doing a backup of repository solution

Postby elyod_72 » Thu Jul 13, 2006 7:55 pm

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?
elyod_72
 
Posts: 198
Joined: Tue Dec 28, 2004 12:45 am
Location: Hollywood, CA.

Postby Harjo » Thu Jul 13, 2006 8:52 pm

yes: see repository (under file-menu) export solution! :-)
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Postby Jan Aleman » Thu Jul 13, 2006 9:50 pm

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

Code: Select all
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!
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby elyod_72 » Thu Jul 13, 2006 9:55 pm

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
 
Posts: 198
Joined: Tue Dec 28, 2004 12:45 am
Location: Hollywood, CA.

Postby Jan Aleman » Thu Jul 13, 2006 10:03 pm

elyod_72 wrote: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.
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby ngervasi » Thu Jul 13, 2006 11:32 pm

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.

Code: Select all
// 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()
Nicola Gervasi
sintpro.com
SAN Partner
ngervasi
 
Posts: 1485
Joined: Tue Dec 21, 2004 12:47 pm
Location: Arezzo, Italy

Postby Westy » Fri Jul 14, 2006 3:19 pm

On Windows using Sybase I create automated backups using a bat file for each day of the week. For example, for Monday I use:
Code: Select all
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
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Postby ROCLASI » Fri Jul 14, 2006 3:49 pm

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.
Code: Select all
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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Postby ROCLASI » Fri Jul 14, 2006 3:55 pm

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Postby elyod_72 » Fri Jul 14, 2006 5:19 pm

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
 
Posts: 198
Joined: Tue Dec 28, 2004 12:45 am
Location: Hollywood, CA.

Postby ngervasi » Fri Jul 14, 2006 6:50 pm

elyod_72 wrote: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.
Nicola Gervasi
sintpro.com
SAN Partner
ngervasi
 
Posts: 1485
Joined: Tue Dec 21, 2004 12:47 pm
Location: Arezzo, Italy

Postby faheemhameed » Thu Mar 15, 2007 12:47 pm

Hi Westy,

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

Thanks for sharing!
Hameed
Pilot simple software
Hong Kong
User avatar
faheemhameed
 
Posts: 763
Joined: Wed Sep 10, 2003 7:23 am

Postby faheemhameed » Thu Mar 15, 2007 12:55 pm

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!
Hameed
Pilot simple software
Hong Kong
User avatar
faheemhameed
 
Posts: 763
Joined: Wed Sep 10, 2003 7:23 am

Re:

Postby rogel » Wed Sep 14, 2011 4:04 am

ngervasi wrote:
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!
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am


Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests

cron