Giter Club home page Giter Club logo

sql-backup's Introduction

SQL BACKUP

You can backup your mysql, mssql, postgresql databases and upload them to digital ocean spaces.

Supports linux and windows. Feel free to fork and develop!

Get Started

First create directory and get in it.

mkdir -p /home/90px-backup/ && mkdir -p /home/90px-backup/backups/ && chmod -R 777 /home/90px-backup/backups/ && cd /home/90px-backup/

Then install necessary python libraries for the project to work correctly. If pip is not working, you can try the pip3 command.

wget -N https://raw.githubusercontent.com/90pixel/sql-backup/main/requirements.txt
chmod +x requirements.txt
sudo -H pip install --ignore-installed PyYAML
pip install -r requirements.txt

Let's download and start our backup script. If python3 not exist, you can try python command.

wget -N https://raw.githubusercontent.com/90pixel/sql-backup/main/backup-script.py
chmod +x backup-script.py
python3 backup-script.py

Screenshots

For the first run, if the config file is not found, you must enter the digital ocean spaces information Config Settings

You can choose option 1 to enter new sql information to be backed up Option Settings

Option Settings

If the database informations is correct the config will be added successfully

Add Database Config

Auto Backup

If you want use sqlcmd and not linked to /usr/local/bin/sqlcmd, you can use this command to create a symbolic link.

sudo ln -s /opt/mssql-tools/bin/sqlcmd /usr/local/bin/sqlcmd

You can start via -backup arguments. To auto backup and add to cronjob. You should add path for cronjob.

cd /home/90px-backup/ && python3 backup-script.py -backup

Crontab ready to use. Every day at 3:05 AM (If the server time is in utc, it will be 06:05 in Turkey time)

# Backup db and upload
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
5 3 * * * cd /home/90px-backup/ && python3 backup-script.py -backup >> backup.log 2>&1

TODO LIST

Todo

  • Extra backup options can be added (google drive, local, ftp)
  • The cronjob task can be set from within the script for ubuntu(linux)
  • Can be automatically added to the task scheduler for windows
  • Log system can be improved
  • In case of error, you can send an e-mail or a notification can be sent from discord.
  • Add port option other than default port
  • Ssh tunnel connection to database

In Progress

  • None

Done ✓

  • Delete old backups older than 3 months
  • Create init commit

sql-backup's People

Contributors

ozgur-d avatar cagrisungur avatar

Stargazers

Ceren avatar Tamer Ağaoğlu avatar  avatar  avatar

Watchers

Muhittin Özer avatar  avatar

Forkers

tamert

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.