mirror of
https://github.com/xzeldon/vwdump.git
synced 2025-06-28 06:18:15 +03:00
Add functionality to delete old backups
This commit is contained in:
parent
766e9bbd0b
commit
54e734beb0
@ -15,6 +15,7 @@ ENV UID 100
|
|||||||
ENV GID 100
|
ENV GID 100
|
||||||
ENV CRONFILE /etc/crontabs/root
|
ENV CRONFILE /etc/crontabs/root
|
||||||
ENV LOGFILE /app/log/backup.log
|
ENV LOGFILE /app/log/backup.log
|
||||||
|
ENV DELETE_AFTER 0
|
||||||
|
|
||||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
COPY backup.sh /app/
|
COPY backup.sh /app/
|
||||||
|
@ -17,6 +17,11 @@ Example for hourly backups
|
|||||||
docker run -d --restart=always --name bitwarden_backup --volumes-from=bitwarden -e CRON_TIME="0 * * * *" bruceforce/bw_backup
|
docker run -d --restart=always --name bitwarden_backup --volumes-from=bitwarden -e CRON_TIME="0 * * * *" bruceforce/bw_backup
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example for backups that delete after 30 days
|
||||||
|
```sh
|
||||||
|
docker run -d --restart=always --name bitwarden_backup --volumes-from=bitwarden -e DELETE_AFTER=30 bruceforce/bw_backup
|
||||||
|
```
|
||||||
|
|
||||||
### Manual Backups
|
### Manual Backups
|
||||||
You can use the crontab of your host to schedule the backup and the container will only be running during the backup process.
|
You can use the crontab of your host to schedule the backup and the container will only be running during the backup process.
|
||||||
|
|
||||||
@ -45,6 +50,7 @@ docker run --rm --volumes-from=bitwarden -v /tmp/myBackup:/myBackup --entrypoint
|
|||||||
| GID | Group ID to run the cron job with |
|
| GID | Group ID to run the cron job with |
|
||||||
| LOGFILE | Path to the logfile *inside* the container |
|
| LOGFILE | Path to the logfile *inside* the container |
|
||||||
| CRONFILE | Path to the cron file *inside* the container |
|
| CRONFILE | Path to the cron file *inside* the container |
|
||||||
|
| DELETE_AFTER | Delete old backups after X many days |
|
||||||
|
|
||||||
## Common erros
|
## Common erros
|
||||||
### Wrong permissions
|
### Wrong permissions
|
||||||
|
11
backup.sh
11
backup.sh
@ -7,13 +7,20 @@ fi
|
|||||||
|
|
||||||
if [ $TIMESTAMP = true ]
|
if [ $TIMESTAMP = true ]
|
||||||
then
|
then
|
||||||
BACKUP_FILE="$(echo "$BACKUP_FILE")_$(date "+%F-%H%M%S")"
|
FINAL_BACKUP_FILE="$(echo "$BACKUP_FILE")_$(date "+%F-%H%M%S")"
|
||||||
|
else
|
||||||
|
FINAL_BACKUP_FILE=$BACKUP_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
/usr/bin/sqlite3 $DB_FILE ".backup $BACKUP_FILE"
|
/usr/bin/sqlite3 $DB_FILE ".backup $FINAL_BACKUP_FILE"
|
||||||
if [ $? -eq 0 ]
|
if [ $? -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "$(date "+%F %T") - Backup successfull"
|
echo "$(date "+%F %T") - Backup successfull"
|
||||||
else
|
else
|
||||||
echo "$(date "+%F %T") - Backup unsuccessfull"
|
echo "$(date "+%F %T") - Backup unsuccessfull"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -z $DELETE_AFTER ] && [ $DELETE_AFTER -gt 0 ]
|
||||||
|
then
|
||||||
|
find $(dirname "$BACKUP_FILE") -name "$(basename "$BACKUP_FILE")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \;
|
||||||
|
fi
|
Loading…
x
Reference in New Issue
Block a user