Database Backup Script

last edited on: Sept. 7, 2021


Disclaimer
The information in this document is provided on an as-is basis. You use it at your own risk. We accept no responsibility for errors or omissions, nor do we have any obligation to provide support for implementing or maintaining the backup script and procedure described here. Furthermore, we do not warrant that the design presented here is appropriate for your requirements.
Nasuni can provide assistance on a professional services basis with developing and implementing backup strategies. For more information, please contact support@nasuni.com.


We recommend that customers make regular backups of their Access Anywhere databases in line with their recovery objectives. Several strategies can be used to achieve this, some of which include making logical backups of the contents of the database. NAA offers a script to assist with making those logical backups, and this page explains how to use that script.

Overview

The database backup script, SMEDBbackup.py, is intended for use by customers using an all-in-one Access Anywhere, a Access Anywhere with an external database running on a Access Anywhere node or a Access Anywhere with a replicant database running on a Access Anywhere node.

When the database backup script is run it creates a MySQL dump file containing commands to recreate and repopulate Access Anywhere's tables. This file can be used as input to MySQL to completely replace the contents of Access Anywhere's database.

Dependencies

Python

The script is written in Python and requires a suitable version of Python for execution. The Python at /usr/var/python on any recent Access Anywhere node is suitable.

SMTP

The script sends an email reporting the result of each execution. To use the script you will have to provide an SMTP server that is accessible to the host on which the script runs, and credentials for an account that can use the SMTP server to send emails.

Downloading the Script

The script is available for download here.

Configuring the Script


Database Name

The script as downloaded will use Access Anywhere database's default name smestorage. If the database you will be backing up has a different name, find the dbname assignment in the script and update the name.

dbName = "smestorage"


Email Settings

At the end of each execution the script sends an email. You can configure the script to use your SMTP server and to control various aspects of the email messages.

SMTP Credentials


Find the line in the script that logs in to the SMTP server and replace the credentials with the values in use for your email account.

server.login("#LOGIN#", "#PASSWORD#")


'From' E'mail addresse

Replace the dummy value for fromaddr with the values you want for the sender email addresses.

        fromaddr = "#FROM EMAIL#"


'To' E'mail addresses

Replace the dummy values for toaddr with the value you want for the recipient email addresses. You can include a list of recipients by separating them with commas.

	toaddr = ["#TO EMAIL1#", "#TO EMAIL2#"]


Email Subject

Customize the subject line as you see fit. At a minimum you should replace the dummy value for CUSTOMER.

msg['Subject'] = "#CUSTOMER# DB Backup Logs {0}".format(logStatus)


SMTP Connection Encryption

Your SMTP server may require SSL encryption or TLS encryption. You can adapt the script for SSL or TLS as described in the script's comments. Either way, you have to replace the dummy value with the name of your email server.

#For SSL instead of TLS replace server line with the line below, and comment server.starttls()
#server = smtplib.SMTP_SSL('#mail.sslprovider.com#', 465)
	
server = smtplib.SMTP('#smtp.gmail.com#', 587)
server.starttls()


Backup Files Management Settings


Each time it runs the script creates a database backup file. It also removes old backups. You can control the directory in which the backup files are stored and the number of days of backup files that are retained.

Number of Days for File Retention

The default value is 14. Change the value assigned to keepDays as you see fit. Bear in mind that the backup files may be large, so you may not want to keep too many of them.

keepDays = 14


Backup Directory

By default the script will write backup files to the /root/dbBackups/ directory. You can override this default by changing the vale assigned to backupDir.

backupDir = '/root/dbBackups/'

You can also override the backup directory setting in the script by specifying a different directory on the command line when you run the script. See the Command Line Arguments section of this document for more details.


Creating the Backups Directory

The script will not create the backup directory. You should create it before running the script.

Running the Script

Run the script as root on Access Anywhere node that hosts the database to be backed up.

The script can be run with zero, one or two command line arguments.

Running the Script With No Command Line Arguments

The simplest invocation of the script looks like this:

/usr/bin/python <path_to_script_directory>/SMEDBbackup.py


Command Line Arguments

You can use neither, other or both of these arguments when running the script.

Output Directory

Use the output directory flag to override the directory that is set in the script.

/usr/bin/python <path_to_script_directory>/SMEDBbackup.py -o <path_of_output_directory>


Replica Mode

The script can be run in either of two modes, default and replica. Default mode assumes that Access Anywhere and its database are running in an all-in-one configuration. In the default mode services that allow access to Access Anywhere will be stopped prior to the backup being taken and restarted after the backup has been made. The Access Anywhere will not be available for normal use while the services are stopped.

Replica mode assumes that Access Anywhere is running with a second, replicant database. Instead of stopping service, replica mode stops the application of replicated changes to the database prior to taking the backup, and restarts the application of replicated changes when the backup is complete. In this mode access to Access Anywhere is not interrupted.

You can use the replica flag ('r') with a value of '1' to run the script in replica mode:

/usr/bin/python <path_to_script_directory>/SMEDBbackup.py -r 1


When using replica mode, run the script on the replicant database host machine.

Running the Script from cron

You may want to run the script from cron. If so, add the appriate entry to root's cron table. A typical cron entry might look like this:

30 20 * * * /bin/python /rootBackupScript/SMEDBbackup.py -r 1


Customize the cron entry to meet your requirements.