Automating database rotation
Although you can do database rotation manually using Audit Manager, you might want to automate the process to perform it automatically on a regular schedule. You might also want to automate and schedule the detachment of old databases from the audit store. The API described in the reference enables you to write scripts to perform database rotation and attach or detach databases.
The software development kit (SDK) for auditing includes four sample scripts that you can modify to suit your purposes: two VBScript samples and two Power Shell samples. One pair of sample scripts (
db_rotation) use default database settings. The second pair (
db_rotation_sql_script) let you customize the database scripts to set up the database and the server.
The sample scripts perform the following steps:
- Create a new audit store database and attach it to an audit store.
- Grant permission to the management database and collectors to access the newly created audit store database.
- Make the newly created audit store database the active database.
- Detach any audit store databases older than two years.
- Publish the settings to Active Directory so that audited computers and collectors can look up the information.
Note that the sample scripts require the user to respond to informational messages at various points during execution. To make these scripts run without user interaction, remove or comment out all the
wscript.echo commands in the script, or redirect the echo commands to STDOUT so that the scheduled task will not hang waiting for user input.
The following command adds the script
db_rotation.vbs as a monthly scheduled task named
rolldb to be run as user
domain_name\administrator. By using
cscript.exe to launch the script, it redirects output to STDOUT.
PS C:\Program Files\Centrify\Audit\SDK\Samples> schtasks.exe /Create /TN "rolldb" /TR "cscript.exe 'C:\Program Files\Centrify\Audit\SDK\Samples\db_rotation.vbs' DefaultInstallation DefaultAuditStore sqlserver.domain_name.com subtest3" /RU domain_name\administrator /SC Monthly /MO 1
The components of this command are as follows:
Schtasks.exe /Create /TN <Task_name> /TR <Task_Command> /RU <Run_As_User> /SC <Reoccurance_rate> /MO <Reoccurance_increment>
cscript.exe 'C:\Program Files\Centrify\Audit\SDK\Samples\db_rotation.vbs' DefaultInstallation DefaultAuditStore sqlserver.domain_name.com subtest3
The task command consists of the following elements:
parser> '<install_path>\<VBS_script>' <Installation> <auditstore> <DB_Server> <DB_prefix>
The prefix is attached to a date stamp in the name of the newly created audit store database.