This "simple" script allows you to backup your application files and databases with possibility to move all backups to remote server.
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 ]
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 configurationKEEP_ONE_COPY_ON_LOCALallows 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' )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"
)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"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=2Set 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"Set your PostgreSQL user to run dump command under main PostgreSQL user.
PGSQL_USER="postgres"REMOTE_HOST="user@host"
REMOTE_DESTINATION="~/backups"
KEEP_ONE_COPY_ON_LOCAL=true # keeps one of each locally on machineOption to create incremental daily backups with using MONTHLY and WEEKLY backups as full.
BACKUP_DAILY_INCREMENTAL=trueM - 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 |
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
# ...