GlassFish 3.1: Automatic Domain Backup
By Chris Kasso on Feb 28, 2011
In a prior post I wrote about the commands we reintroduced in GlassFish 3.1 which allows administrators to manually backup and restore a GlassFish domain. There is more to it than that. We also introduced support for scheduled automatic backups of a domain. This new feature is only available in Oracle GlassFish Server. For those who are not familiar with Oracle GlassFish Server this is our commercial distribution of the GlassFish Server Open Source Edition. Oracle GlassFish Server is backed by support from Oracle and is distributed with GlassFish Server Control which is a collection of additional features which enhance the functionality of Oracle GlassFish Server.
Here is a short summary of how it works. It is pretty simple. You basically create a new object called a Backup Configuration (this named object describes the type of backup you want to perform). You associate the Backup Configuration with a named Schedule. Multiple Backup Configurations can exists (some enabled, some not) and they can point to the same schedule or different schedules.
The Backup Config has the following attributes:
- Enabled (Boolean)
- Backup Location
- Recycle Limit
- Live Backup (Boolean)
- Backup Type (Full or Config Only)
The Name is the name of the Backup Configuration and you can create as many of these as you like. Each Backup Configuration must be associated with an existing schedule. The product ships with three pre-defined schedules: daily, weekly and monthly but you can create more or modify the existing schedules. A Backup Configuration is enabled by default but you can change the Enabled attribute to temporarily turn off a scheduled backup. If you do not specify a backup location the backups (in the form of zip files) are maintained in the domain directory (backups subdirectory). The recycle limit allows you to control the number of prior backups to maintain. The default is 25. When that number is reached older backups are deleted as new ones are added. The live backup option allows the backup to be performed on the DAS without suspending it (more on that in a future posting). Finally you can control whether a full backup is performed, which is the entire domain directory (sans existing backup files), or just the domain's configuration.
A good practice might be to perform a full backup of the domain once or twice a month and perform configuration only backups daily.
Here's a quick example using the asadmin CLI to create these two automatic backups. You can also perform the same operation using the GlassFish Console which I will demonstrate in a different blog entry.
First I'll list the existing schedules:
% asadmin list-schedules --long NAME SECOND MINUTE HOUR DAY OF WEEK DAY OF MONTH MONTH YEAR daily 0 0 0 \* \* \* \* weekly 0 0 0 Sun \* \* \* monthly 0 0 0 \* 1 \* \* Command list-schedules executed successfully.
So as you can see there are three existing schedules. The daily schedule defines an event which occurs every day at midnight. The weekly defines an event to occur every Sunday at midnight and the monthly schedule defines an event to occur on the first day of the month also at midnight.
I'll create a new backup config to perform our monthly full backup of the domain directory:
% asadmin create-backup-config --schedule monthly --backupdir /tmp/das-backups --recyclelimit 12 d1-full Command create-backup-config executed successfully.
The above command creates a backup config which is associated with the monthly schedule. The backups which are created are stored in /tmp/das-backups and I'm using the recyclelimt option to control the number of backups I will maintain (twelve in this case).
The next command:
% asadmin create-backup-config --schedule daily --backupdir /tmp/das-backups --recyclelimit 30 --configonly d1-config Command create-backup-config executed successfully
creates another backup config which kicks off a backup daily. This backup config will only backup the contents of the config directory for the domain. Since this backup config is associated with the daily schedule the backup will occur every day.
It is worth noting that multiple backup configs can reference the same schedule. They will both get executed at the same time although the order in which they will be executed is not defined.
If you want to see the details of a specific backup config you can use the new list-backup-configs subcommand:
% asadmin list-backup-configs --long d1-config Name of Backup Config :d1-config Auto Backup Enabled :true Schedule :daily Recycle Limit :30 Config Only backup :true Active Backup Enabled :false Backup Directory :/tmp/das-backups Last Backup Attempt :Mon Feb 28 14:05:55 PST 2011 Last Successful Backup :Mon Feb 28 14:05:55 PST 2011 Schedule Details: NAME SECOND MINUTE HOUR DAY OF WEEK DAY OF MONTH MONTH YEAR daily 0 0 0 \* \* \* \* Command list-backup-configs executed successfully.
The backups will be performed as long as the Domain Administration Server (DAS) is running. When the event is scheduled to occur the DAS will suspend the domain temporarily. When the domain is suspended any command which would cause the DAS to modify the domain directory is blocked (other commands such as list-clusters are allowed). This allows the backup to be safely performed. Once complete the DAS is resumed so that all operations are allowed.
You can use the list-backups command to list available backups. In this example I'll look at the backups available in the /tmp/backups directory:
% asadmin list-backups --backupdir /tmp/das-backups CONFIG USER BACKUP DATE FILENAME d1-config kasso Thu Feb 24 00:00:00 PST 2011 domain1_2011_02_24_v00005.zip d1-config kasso Fri Feb 25 00:00:00 PST 2011 domain1_2011_02_25_v00006.zip d1-config kasso Sat Feb 26 00:00:00 PST 2011 domain1_2011_02_26_v00007.zip d1-config kasso Sun Feb 27 00:00:00 PST 2011 domain1_2011_02_27_v00008.zip d1-config kasso Mon Feb 28 00:00:02 PST 2011 domain1_2011_02_28_v00009.zip d1-full kasso Wed Feb 23 10:49:47 PST 2011 domain1_2011_02_23_v00001.zip Command list-backups executed successfully.
If you wanted to restore the lastest backup of the domain you would stop the domain and then use the restore-domain command:
% asadmin stop-domain Waiting for the domain to stop ...... Command stop-domain executed successfully. % asadmin restore-domain --backupdir /tmp/das-backups --backupconfig d1-full domain1 Restored the domain (domain1) to /work/ogs/glassfish3/glassfish/domains/domain1 Command restore-domain executed successfully.
This replaces the contents of the domain directory with the contents of the full backup of the domain.
For additional details about creating backup configurations and schedules see the Oracle GlassFish Server 3.1 Administration Guide.