remove old backups
This commit is contained in:
parent
c212a70020
commit
d3136a5439
@ -15,6 +15,7 @@ REMOTE_USER="tom"
|
||||
REMOTE_HOST="nordicdatarefinement.com"
|
||||
REMOTE_PORT="23"
|
||||
REMOTE_DIR="/mnt/hdd/gitea-backup"
|
||||
REMOTE_KEEP_OLD=7
|
||||
|
||||
REQUIRED_PROGRAMS=("rsync" "mysqldump" "zstd" "tar" "systemctl" "openssl")
|
||||
for prog in "${REQUIRED_PROGRAMS[@]}"; do
|
||||
@ -87,3 +88,19 @@ log "Backups sent successfully."
|
||||
|
||||
log "Removing dumps locally"
|
||||
rm -r "${BACKUP_DIR}"
|
||||
|
||||
log "Cleaning up old backups on remote server, keeping ${REMOTE_KEEP_OLD}..."
|
||||
|
||||
ssh -p ${REMOTE_PORT} ${REMOTE_USER}@${REMOTE_HOST} <<EOF
|
||||
REMOTE_KEEP_OLD=${REMOTE_KEEP_OLD}
|
||||
REMOTE_DIR=${REMOTE_DIR}
|
||||
|
||||
sqls=\$(ls ${REMOTE_DIR}/gitea-database-backup-*.sql.zst.enc 2>/dev/null)
|
||||
if [ \$(echo "\${sqls}" | wc -l) -gt ${REMOTE_KEEP_OLD} ]; then
|
||||
echo "\${sqls}" | sort | head -n -${REMOTE_KEEP_OLD} | xargs -I {} rm -- {}
|
||||
fi
|
||||
tars=\$(ls ${REMOTE_DIR}/gitea-backup-*.tar.zst.enc 2>/dev/null)
|
||||
if [ \$(echo "\${tars}" | wc -l) -gt ${REMOTE_KEEP_OLD} ]; then
|
||||
echo "\${tars}" | sort | head -n -${REMOTE_KEEP_OLD} | xargs -I {} rm -- {}
|
||||
fi
|
||||
EOF
|
||||
|
Loading…
x
Reference in New Issue
Block a user