Renamed backing.sh to backin_N_packin.sh and improved file with variables and retention plan.
This commit is contained in:
39
backin_N_packin.sh
Executable file
39
backin_N_packin.sh
Executable file
@@ -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
|
25
backing.sh
25
backing.sh
@@ -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
|
Reference in New Issue
Block a user