diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83e9d13..e1443ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,7 @@ jobs: POSTGRES_PASSFILE_STORE: "**None**" POSTGRES_CLUSTER: "FALSE" BACKUP_SUFFIX: ".sql.gz" + BACKUP_LATEST_TYPE: "symlink" BACKUP_KEEP_DAYS: 7 BACKUP_KEEP_WEEKS: 4 BACKUP_KEEP_MONTHS: 6 @@ -72,6 +73,7 @@ jobs: POSTGRES_PORT: 5432 POSTGRES_EXTRA_OPTS: "-Z0 -Fd" BACKUP_SUFFIX: "" + BACKUP_LATEST_TYPE: "symlink" BACKUP_DIR: ".data" # Defaults POSTGRES_DB_FILE: "**None**" @@ -108,6 +110,7 @@ jobs: POSTGRES_PASSWORD_FILE: "**None**" POSTGRES_PASSFILE_STORE: "**None**" BACKUP_SUFFIX: ".sql.gz" + BACKUP_LATEST_TYPE: "symlink" BACKUP_KEEP_DAYS: 7 BACKUP_KEEP_WEEKS: 4 BACKUP_KEEP_MONTHS: 6 diff --git a/README.md b/README.md index 8e9f809..9e317bc 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Most variables are the same as in the [official postgres image](https://hub.dock | BACKUP_KEEP_WEEKS | Number of weekly backups to keep before removal. Defaults to `4`. | | BACKUP_KEEP_MONTHS | Number of monthly backups to keep before removal. Defaults to `6`. | | BACKUP_KEEP_MINS | Number of minutes for `last` folder backups to keep before removal. Defaults to `1440`. | +| BACKUP_LATEST_TYPE | Type of `latest` pointer (`symlink`,`hardlink`,`none`). Defaults to `symlink`. | | HEALTHCHECK_PORT | Port listening for cron-schedule health check. Defaults to `8080`. | | POSTGRES_DB | Comma or space separated list of postgres databases to backup. If POSTGRES_CLUSTER is set this refers to the database to connect to for dumping global objects and discovering what other databases should be dumped (typically is either `postgres` or `template1`). Required. | | POSTGRES_DB_FILE | Alternative to POSTGRES_DB, but with one database per line, for usage with docker secrets. | diff --git a/alpine.Dockerfile b/alpine.Dockerfile index e930ca8..943999c 100644 --- a/alpine.Dockerfile +++ b/alpine.Dockerfile @@ -23,6 +23,7 @@ ENV POSTGRES_DB="**None**" \ SCHEDULE="@daily" \ BACKUP_DIR="/backups" \ BACKUP_SUFFIX=".sql.gz" \ + BACKUP_LATEST_TYPE="symlink" \ BACKUP_KEEP_DAYS=7 \ BACKUP_KEEP_WEEKS=4 \ BACKUP_KEEP_MONTHS=6 \ diff --git a/backup.sh b/backup.sh index ac9fd21..fd3abb2 100755 --- a/backup.sh +++ b/backup.sh @@ -121,14 +121,22 @@ for DB in ${POSTGRES_DBS}; do ln -vf "${FILE}" "${MFILE}" fi # Update latest symlinks - echo "Point last backup file to this last backup..." - ln -svf "${LAST_FILENAME}" "${BACKUP_DIR}/last/${DB}-latest${BACKUP_SUFFIX}" - echo "Point latest daily backup to this last backup..." - ln -svf "${DAILY_FILENAME}" "${BACKUP_DIR}/daily/${DB}-latest${BACKUP_SUFFIX}" - echo "Point latest weekly backup to this last backup..." - ln -svf "${WEEKLY_FILENAME}" "${BACKUP_DIR}/weekly/${DB}-latest${BACKUP_SUFFIX}" - echo "Point latest monthly backup to this last backup..." - ln -svf "${MONTHY_FILENAME}" "${BACKUP_DIR}/monthly/${DB}-latest${BACKUP_SUFFIX}" + LATEST_LN_ARG="" + if [ "${BACKUP_LATEST_TYPE}" = "symlink" ]; then + LATEST_LN_ARG="-s" + fi + if [ "${BACKUP_LATEST_TYPE}" = "symlink" -o "${BACKUP_LATEST_TYPE}" = "hardlink" ]; then + echo "Point last backup file to this last backup..." + ln "${LATEST_LN_ARG}" -vf "${LAST_FILENAME}" "${BACKUP_DIR}/last/${DB}-latest${BACKUP_SUFFIX}" + echo "Point latest daily backup to this last backup..." + ln "${LATEST_LN_ARG}" -vf "${DAILY_FILENAME}" "${BACKUP_DIR}/daily/${DB}-latest${BACKUP_SUFFIX}" + echo "Point latest weekly backup to this last backup..." + ln "${LATEST_LN_ARG}" -vf "${WEEKLY_FILENAME}" "${BACKUP_DIR}/weekly/${DB}-latest${BACKUP_SUFFIX}" + echo "Point latest monthly backup to this last backup..." + ln "${LATEST_LN_ARG}" -vf "${MONTHY_FILENAME}" "${BACKUP_DIR}/monthly/${DB}-latest${BACKUP_SUFFIX}" + else # [ "${BACKUP_LATEST_TYPE}" = "none" ] + echo "Not updating lastest backup." + fi #Clean old files echo "Cleaning older files for ${DB} database from ${POSTGRES_HOST}..." find "${BACKUP_DIR}/last" -maxdepth 1 -mmin "+${KEEP_MINS}" -name "${DB}-*${BACKUP_SUFFIX}" -exec rm -rvf '{}' ';' diff --git a/debian.Dockerfile b/debian.Dockerfile index af5db09..6fe7e50 100644 --- a/debian.Dockerfile +++ b/debian.Dockerfile @@ -37,6 +37,7 @@ ENV POSTGRES_DB="**None**" \ SCHEDULE="@daily" \ BACKUP_DIR="/backups" \ BACKUP_SUFFIX=".sql.gz" \ + BACKUP_LATEST_TYPE="symlink" \ BACKUP_KEEP_DAYS=7 \ BACKUP_KEEP_WEEKS=4 \ BACKUP_KEEP_MONTHS=6 \