Giter Site home page Giter Site logo

paulocoghi / auto-mysql-backup Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 15 KB

Shell script to create MySQL backups. Can be used manually or via cron jobs

Shell 100.00%
mysql-backup mysql-backup-ssh mysql-backup-ftp backup-mysql cronjob cron auto-deletion auto-delete

auto-mysql-backup's Introduction

auto-mysql-backup

Shell script to create MySQL backups. Can be used manually or via cron jobs. Created specially to my friend, Pasquale.

PRs are welcome! If you want to contribute, let's make this tool the best one to MySQL backups, together!

For support, just open an issue!

Installation

$ wget https://raw.githubusercontent.com/paulocoghi/auto-mysql-backup/master/auto-mysql-backup.sh
$ chmod +x auto-mysql-backup.sh
$ sudo mv auto-mysql-backup.sh /usr/bin/auto-mysql-backup

Instructions

Local backup

$ auto-mysql-backup -d [database_name] -u [user_name] -p [password] -l [/path/to/backup/directory/]

Local database with remote backup (via scp/ssh)

$ auto-mysql-backup -d [database_name] -u [user_name] -p [password] -i [/path/to/public/ssh/key] -l [username@hostname:/path/to/backup/directory/]

Using cron jobs

First, define your frequency. You can use https://crontab.guru/ to create one. For example, every 1:00am, run:

$ crontab -e

And insert:

0 1 * * * auto-mysql-backup -d [database_name] -u [user_name] -p [password] -l [/path/to/backup/directory/] > /dev/null 2>&1

the first column is the minute, the second is the hour, the third is the day, the fourth is the month and the fifth is the day of week (0-6)

Removing old backups

You can add another cron job to erase backups that are X days old, that can run before the backup (for example, one hour before), with the line:

0 0 * * * find /path/to/backup/directory/ -mindepth 1 -type f -mtime +5 -delete

in this example, the +5 is specifying that files older than 5 days must be deleted

Thanks to

  • Pasquale

auto-mysql-backup's People

Contributors

paulocoghi avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

mnhsaki

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.