]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Creating checksums and removing old backups
authorFrank Brehm <frank@brehm-online.com>
Tue, 20 Apr 2021 05:53:39 +0000 (07:53 +0200)
committerFrank Brehm <frank@brehm-online.com>
Tue, 20 Apr 2021 05:53:39 +0000 (07:53 +0200)
bin/manual-backup

index 16985265f731290c347c0fb30a54738f4a03ba28..12d65bce6d5db5d4e1e37d72b5668e538cc84a42 100755 (executable)
@@ -243,6 +243,79 @@ do_mysql_backup(){
 
 }
 
+#------------------------------------------------------------------------------
+create_checksums() {
+
+    info "Creating checksum files ..."
+
+    if [[ -d "${BACKUP_DIR}" ]] ; then
+        cd "${BACKUP_DIR}"
+    fi
+
+    local cs_type=
+    local cs_file=
+    local cmd=
+
+    for cs_type in "md5" "sha1" "sha256" ; do
+        cs_file="backup-checksums.${cs_type}"
+        info "Creating '${CYAN}${cs_file}${NORMAL}' ..."
+        cmd="${cs_type}sum *.gz > \"${cs_file}\""
+        if [[ "${SIMULATE}" == "y" ]] ; then
+            info "Executing: ${cmd}"
+            continue
+        fi
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+    done
+
+}
+
+#------------------------------------------------------------------------------
+clean_old_backups() {
+
+    info "Removing old backup sets - separation date: '${CYAN}${REMOVE_DATE}${NORMAL}'."
+
+    local i=0
+    local bdir=
+    local bdir_base=
+
+    for bdir in $( ls -1 -d -r "${BACKUP_HOSTDIR}"/* ) ; do
+
+        bdir_base=$( basename "${bdir}" )
+        if [[ "${bdir_base}" == 'lost+found' ]] ; then
+            continue
+        fi
+
+        if [[ ! -d "${bdir}" ]] ; then
+            debug "Path '${CYAN}${bdir}${NORMAL}' is not a directory."
+            continue
+        fi
+
+        if [[ "${bdir}" == "${BACKUP_DIR}" ]] ; then
+            continue
+        fi
+
+        if [[ "${bdir_base}" =~ ^20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]$ ]] ; then
+            :
+        else
+            continue
+        fi
+
+        debug "Checking '${CYAN}${bdir}${NORMAL}' for removing ..."
+        i=$(( $i + 1 ))
+
+        if [[ ${i} -le ${BACKUP_COPIES} ]] ; then
+            continue
+        fi
+
+        info "Removing '${bdir}' ..."
+        RM --recursive "${bdir}"
+
+
+    done
+
+}
+
 #------------------------------------------------------------------------------
 main() {
 
@@ -252,6 +325,8 @@ main() {
     check_preferences
     do_dir_backup
     do_mysql_backup
+    create_checksums
+    clean_old_backups
 
     info "Finished."
 }