Bash script to backup and restore databases and files on web servers.
The backup script uses a configuration file where each website is set as a project and can have multiple databases and folder paths for backup. Each backup file is also copied over to a remote location (over SCP/SSH).
Currently works with MySQL and PostgreSQL databases.
- json.sh (included as git submodule)
-
Clone project with
--recursive
option to recursively clone the json.sh submodule.> git clone --recursive git@github.com:miranj/backup.git
-
Create a
config.json
fromconfig-sample.json
using appropriate config values. -
Protect
config.json
.> chmod 600 config.json
-
For PostgreSQL, a
.pgpass
file must be placed in the user home directory with database usernames and passwords. Refer PostgreSQL Password File Documentation. -
For MysQL, a
my.cnf
file may be used to provide database usernames and passwords. Refer MySQL Option File Documentation. -
Set up a cron job to periodically run the script
backup.sh
Examples: > # 3AM everyday > 0 3 * * * <path_to_backup.sh> [--config=<path_to_config.json>] > > # Every 30 minutes > 0/30 * * * * <path_to_backup.sh> [--config=<path_to_config.json>]
-
To delete old backups specify a lifetime in the config file, and set up a cron job to periodically run the script
cleanup.sh
Example: > # 3AM every Saturday > 0 3 * * 6 <path_to_cleanup.sh> [--config=<path_to_config.json>]
./backup.sh [--config=<path_to_config.json>]
backs up all projects./backup.sh [--config=<path_to_config.json>] <project-name>
backs up a single project./restore.sh [--config=<path_to_config.json>] <project-name> <backup-file-path>
restores the project./cleanup.sh [--config=<path_to_config.json>]
deletes all local backups that are older than the lifetime (as set in config file)./cleanup.sh [--config=<path_to_config.json>] <project-name>
deletes all local backups of a single project that are older than the lifetime (as set in config file)
- Install Roundup.
- Copy the config files in
tests/config-sample
totests/config
using appropriate config values. - At the root of the source code run
./tests.sh
.