# 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] [RET] # #!/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