From 7302baf9fa084c093235614dd6e3e80d968647e3 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Tue, 30 Jul 2024 17:58:49 +0200 Subject: [PATCH] Renamed backing.sh to backin_N_packin.sh and improved file with variables and retention plan. --- backin_N_packin.sh | 39 +++++++++++++++++++++++++++++++++++++++ backing.sh | 25 ------------------------- 2 files changed, 39 insertions(+), 25 deletions(-) create mode 100755 backin_N_packin.sh delete mode 100644 backing.sh diff --git a/backin_N_packin.sh b/backin_N_packin.sh new file mode 100755 index 0000000..11d652c --- /dev/null +++ b/backin_N_packin.sh @@ -0,0 +1,39 @@ +# backin_N_packin.sh +# ------------------ +# +# Compress a folder and store it in given location with a +# specific system user owner +# +# SYNOPSIS +# backing.sh [FILE] [DEST] [SRC] [OWN] +# + +#!/bin/bash + + +DEST="$2" # [DEST] Complete path to store file in +SRC="$3" # [SRC] Folder to be backed up +OWN="$4" # [OWN] Final owner of the file +RET="$5" # Retention integer for days older then, to delete files + # if 0 don't delete anything +COMPRESSER="tar cvfj" # The utility used to compress the data and its arguments +FILEXTENSION=".tar.bz2" # The file extension, usually related to the compression utility +NOW=$(date +"%d-%m-%Y") # The current date formated with, day/month/year +FILE="$1.$NOW$FILEXTENSION" # [FILE] Name of the backed up file + +$COMPRESSER $DEST/$FILE -C $SRC . # Start the backup/compress main process + +back=$! # get the pid number of the backup/compress comand +wait $back # and wait for it to finish +logger "Website dated backup in $DEST - [WEB-BACKUP]" # Log backup time in journalctl +echo -e "\nWebsite dated backup complete.\n" +chown $OWN:$OWN $DEST/$FILE # Change owner of the file + +if [ $RET != 0 ] +then + find $DEST -name "$1.*$FILEXTENSION" -type f -mtime +$RET -delete # Apply retention plan + logger "Backups $1.*$FILEXTENSION older then $RET days deleted - [WEB-BACKUP]" # Log backup delete time in journalctl + echo -e "Backups $1.*$FILEXTENSION older then $RET days deleted - [WEB-BACKUP]" +else + echo -e "Retention plan OFF.\n" +fi diff --git a/backing.sh b/backing.sh deleted file mode 100644 index 0c63b9c..0000000 --- a/backing.sh +++ /dev/null @@ -1,25 +0,0 @@ -# backing.sh -# ---------- -# -# Compress a folder and store it in given location with a -# specific system user owner -# -# SYNOPSIS -# backing.sh [FILE] [DEST] [SRC] [OWN] -# -# by Jony Silva -# Thu 6 Aug 01:40:45 GMT 2015 -# Anti-copyright and/or BeerWare. - - -#!/bin/bash - -NOW=$(date +"%d-%m-%Y") # [NOW] The current date formated with, day/month/year -FILE="$1.$NOW.tar.bz2" # [FILE] Name of the backed up file -DEST="$2" # [DEST] Complete path to store file in -SRC="$3" # [SRC] Folder to be backed up -OWN="$4" # [OWN] Final owner of the file - - -tar cvfj $DEST/$FILE -C $SRC . -chown $OWN.$OWN $DEST/$FILE