Skip to content

tobiasz-gleba/backup-db-to-ftp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Universal Backup ⇆ Restore with FTP/SFTP

A Typer-based command-line tool that can backup and restore:

  • MongoDB databases (via mongodump / mongorestore)
  • MySQL databases (via mysqldump / mysql)
  • Filesystem folders (via tar)

Backups are compressed into timestamped .tar.gz archives and pushed to an FTP/SFTP server with an optional retention policy. The same archives can be pulled back and restored with a single command.

# Create backups
python backup.py mongodb --db myapp
python backup.py mysql   --db wordpress --user root
python backup.py folder  /var/www/html

# Restore (from the latest archive if none specified)
python backup.py restore mongodb --db myapp
python backup.py restore mysql   --db wordpress
python backup.py restore folder  /var/www/html

Configuration uses environment variables (see table below) and/or command-line flags. For interactive help, run python backup.py --help or any sub-command with --help.


Dependencies

  • Python ≥ 3.8: pip install typer[all] rich paramiko (paramiko only for SFTP)
  • System binaries: mongodump, mongorestore, mysqldump, mysql, tar

Environment Variable Reference

FTP_HOST         FTP/SFTP server               (required)
FTP_PORT         Port (21 FTP, 22 SFTP)
FTP_USER         Username                      (required)
FTP_PASSWORD     Password                      (required)
FTP_DEST_DIR     Remote dir      (default /backups)
FTP_PROTOCOL     ftp | sftp      (default ftp)
FTP_PASSIVE      true|false      (FTP passive, default true)
RETENTION_DAYS   Days to keep backups (default 7, 0 = keep all)

# MongoDB
MONGO_HOST       localhost   MONGO_PORT    27017
MONGO_USER       -           MONGO_PASSWORD -     MONGO_AUTH_DB  admin

# MySQL
MYSQL_HOST       localhost   MYSQL_PORT    3306
MYSQL_USER       root        MYSQL_PASSWORD -

Cron Example

0 2 * * * /usr/bin/python3 /opt/scripts/backup.py mongodb --db myapp >> /var/log/backup.log 2>&1

About

Simple python container to backup database to the FTP server.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors