bash-backup
bash-backup automates filesystem and MySQL backups, then ships the resulting archives to S3-compatible storage.
Usage
$ git clone git@github.com:newsdict/bash-backup.git
$ cd bash-backup
$ cp env-example .env
Edit the .env file with your backup settings.
$ bash backup.sh [--debug]
Multiple Targets
$ git clone git@github.com:newsdict/bash-backup.git
$ cd bash-backup
$ cp env-example .env-sample1
Edit .env-sample1 with the first target configuration.
$ cp env-example .env-sample2
Edit .env-sample2 with the second target configuration.
$ sh backup.sh [--debug] sample1
$ sh backup.sh [--debug] sample2
Flow
- Archive the selected files and directories.
- Dump the MySQL database, if enabled.
- Bundle the generated artifacts into a final backup archive.
- Upload the result to S3 storage with retention management.
Environments
Temporary Directory
temporary_directory=tmp
Log name
log_name=logs/backup.$now.log
Backup filename
backup_filename=backup
Display messages
display_messages=1
Execute archive
archive=1
Archive paths or files
declare -a archive_paths=(
"/var/www/html"
"/etc/nginx"
)
Compression type of backup
commpression_type=gzip
- gzip: *.tar.gz
- zip: *.zip
- bzip2: *.tar.bz2
Execute database
database=1
Database Type for Dump
declare -A database_conf=(
["engine"]="mysql" # mysql only
["name"]="sample1_database" # database name
["username"]="user1" # username
["password"]="pass" # password
["host"]="127.0.0.1" # host
["port"]=3306 # port
)
Storage type for backup files
storage_type=s3
s3only
S3 settings
declare -A s3_conf=(
["keep"]=5
["access_key"]=""
["secret"]=""
["bucket"]="backup"
["path"]="test"
["region"]="ap-northeast-1"
)
Links
- Source Code (GitHub)
- Author: yubele