Not much code since I’m a bit at a loss on how to start.
I’m trying to create an application that backs up a Derby database and stores the users data. I have the code for the backup itself that can be run manually. I want to create a feature that will check a settings file, and execute a backup at the proper schedule (daily, weekly, monthly). I think I can make it check on start up, but there’s an issue if the application is running, I’d like it to periodically check the time. There’s a good possibility that this application will be left running for days on end.
I also want to allow the users to “sleep” the backup for a few hours if there scheduled time has come.
I can have a Thread.Sleep() called at bootup and have it check every X minute/hours. Similarly if they choose to sleep the backup. I’m not sure if that’s the best way to do it. I assume any API call will probably do the same, but I’m wondering if I’m missing something in handling a thread like that.
Are there any functions/libraries in the Netbeans IDE & Platform that I’m leveraging, that I could hook into to help me build this functionality?
Thanks
Here’s how I implemented it. I changed the method of implementation a bit, so this answer isn’t exactly how the question was worded. I removed the “sleep” feature, but using the code I’m providing you could easily implement it. I have it partially implemented, and I’ll show the code below. It basically involves creating a few classes that implement Runnable. The actual code to run the backup isn’t shown. That would be platform specific anyway, so handle it as you would. We’re using Derby, so that’s how our backups are handled.
I’ll break it down by class & function:
DatabaseBackupReminder. This class handles the prompt to the user that tells them how long since the last backup, and allows them to sleep the reminder for X number of hours. It is a thread itself, so it can be called somewhere else and slept too, so it’s not constantly pinging the DB to see when the last backup was run.
DatabaseBackupController. This class, as it’s named, controls the whole process. From reminder, to executing the actual backup code.
Class DbBackupAction handles the local backup aspect. We backup locally, then send that file offsite in another class.
This implements runnable, so it will handle the backup asynchronously and not cause the whole program to hang up.
BackupRunner handles both onsite/offsite backups. Uses DbBackupAction && RemoteBackupAction
RemoteBackupAction handles FTPing out backup offsite.