Skip to content

MimoGraphix/bash-backup-on-steroids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bash backups on steroids 💪

This "simple" script allows you to backup your application files and databases with possibility to move all backups to remote server.

Usage

Usage: backup.sh    [ --manual ( Creates one manual backup ) ]
                    [ --ignore-database ]
                    [ --ignore-storage ]
                    [ --gpg <email@public.key> ]
                    [ -m | --mode <'local-only' | 'remote-only' | 'local-remote'> ]
                    [ -v | --verbose ]
                    [ -t | --test ]
                    [ -h | --help ]

Configuration

Multiple backup modes

  • local-only - created backup only locally on the machine. NOTE: Be careful this is very storage space consuming.
  • remote-only - move locally created backups to the remote machine. NOTE: Additional configuration KEEP_ONE_COPY_ON_LOCAL allows you to keep one of each backups locally on machine.
  • local-remote - rsync backup files between local and remote server
BACKUP_MODE='local-only' ## Available option ( 'local-only' | 'remote-only' | 'local-remote' )

List of directories to backup

You can backup multiple directories by putting them into array. Use :: as a separator between tar file name and directory

SRC_CODES=(
  "directory1::/srv/application/www"
  "directory2::/srv/application/storage"
)

Protect your backups

You can protect your backups with Public GPG key which allows you to safely moves files between servers and decrypt files only on computer with Private key pair

PUBLIC_KEY="email@public.key"

Timing and retention

You can set how many copies you want to keep and which types of backups you want to have.

BACKUP_DAILY=true   # if set to false backup will not work
BACKUP_RETENTION_DAILY=6

BACKUP_WEEKLY=true  # if set to false backup will not work
BACKUP_RETENTION_WEEKLY=3

BACKUP_MONTHLY=true # if set to false backup will not work
BACKUP_RETENTION_MONTHLY=2

Backup Database

Set your MySQL/MariaBD settings, backup will dump all databases separately except of default mysql databases.

MYSQL_HOST="127.0.0.1"
MYSQL_USER="db-user"
MYSQL_PASSWORD="db-password"

Backup PostgreSQL

Set your PostgreSQL user to run dump command under main PostgreSQL user.

PGSQL_USER="postgres"

Remote server setup

REMOTE_HOST="user@host"
REMOTE_DESTINATION="~/backups"
KEEP_ONE_COPY_ON_LOCAL=true # keeps one of each locally on machine

Incremental Backup Planning

Option to create incremental daily backups with using MONTHLY and WEEKLY backups as full.

BACKUP_DAILY_INCREMENTAL=true

M - Monthly, W - Weekly, D - Daily, i - Incremental

Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu
Day 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30.
Classic M D D D D D W D D D D D D W D D D D D D W D D D D D D W D D
Incr. M Di Di Di Di Di W Di Di Di Di Di Di W Di Di Di Di Di Di W Di Di Di Di Di Di W Di Di

Restore from backup

tar --extract --verbose --listed-incremental=/dev/null --file=PATH_TO_FILE

# in case this is incremental backup you have to start fits first file in chain
# --file=[MONTHLY|WEEKLY].tar
# --file=DAILY_MONDAY.tar
# --file=DAILY_TUESTDAY.tar
# ...

About

Highly customisable bash based backup script

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages