Python script to take Backup of Databases, store it in DigitalOcean Spaces and report the status to Telegram Channel.
- Python 3.8.10 and external Python Modules:
- MySQL Connector:
pip install mysql-connector-python - Boto3:
pip install boto3
- MySQL Connector:
Database:
DB_USERNAME- Username to connect DatabaseDB_PASSWORD- Password to connect of DatabaseDB_DATABASE- Single Database or Comma separated Databases list
DigitalOcean API
DO_SPACES_KEY- Spaces access KeyDO_SPACES_SECRET- Secret generated along with the Spaces access KeyDO_SPACES_REGION- Spaces regionDO_SPACES_BUCKET- Bucket name in the Spaces InstanceDO_SPACES_ENDPOINT- API endpointDO_SPACES_ROOT_FOLDER- (Optional) Base folder to upload the files like name of the Application incase, single Spaces instance is used for multiple applications
Telegram Bot (To report status on Telegram Channel)
TG_BOT_TOKEN- Access token of the Telegram botTG_BOT_CHANNEL_ID- Chat ID in which the Bot has to report the status. Should be obtained via getUpdates method to Telegram Bot API (https://core.telegram.org/bots/api#getupdates) after adding the Bot to a Channel or after Sending 'Hi' to the bot incase of Personal chat
Put this file in the root folder of the application and schedule it using cron
Scheduling using Cron to run at every midnight:
0 0 * * * cd /path-ro-application && /usr/bin/python3 backup-databases.py > log 2>&1