Skip to content

Database Backups Automation

This guide details the process to set up automatic backups for your database using a Python script.

Setup Instructions

Install Python: Ensure Python is installed on your system.

Prepare the Script:

  • Locate and unzip the folder containing
  • Open with a text editor.

Configure the Script:

  • Set the source_folder to the path of your database directory if you use a custom one or keep the default folder if you didn't change it in your server database configuration.
  • Adjust target_folder to where you'd like your backups stored. It is recommended to use a different physical or network drive for the backups. Using a separate drive or a network location ensures that in case your main drive fails, you still have access to a working backup, safeguarding against total data loss.
  • Specify max_backups to control the maximum number of backups to keep.
  • Define backup_interval to set how frequently (in seconds) the backups should occur.

Run the Script: Execute the script from a terminal or command prompt:


How It Works

  • The script creates a backup of the specified source_folder into the target_folder, appending a timestamp to the backup's folder name for easy identification.
  • Old backups are managed based on the max_backups setting, ensuring only the most recent backups are kept.
  • The script runs continuously, performing backups at intervals defined by backup_interval.

Customization Tips

  • Modify the backup_interval according to your backup frequency needs. For example, 60*60*24 for daily backups.


  • It is recommended to use a different drive for the backups, so in case your main drive fails, you still have a working backup.