Fixing bugs with trying to delete /bin or create folders in root
This commit is contained in:
parent
28e3998792
commit
fd4f8d22fe
21
rotate.sh
21
rotate.sh
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Author: Marcello Torchio
|
# Authors: Marcello Torchio, Will Bradley
|
||||||
|
# https://github.com/zyphlar/backup-rotation-script
|
||||||
|
|
||||||
# Set the directory name that you wish to backup
|
# Set the directory name that you wish to backup
|
||||||
DIRTOBACKUP=$1
|
DIRTOBACKUP=$1
|
||||||
|
@ -8,15 +9,21 @@ DIRTOBACKUP=$1
|
||||||
# Set up the backup destination directory
|
# Set up the backup destination directory
|
||||||
BACKUPDIRDEST=$2
|
BACKUPDIRDEST=$2
|
||||||
|
|
||||||
# Set up the number of days for backup rotation
|
# Set up the number of days for backup rotation (archives older than these # of days ago will be deleted)
|
||||||
NUMDAYS=7;
|
NUMDAYS=7;
|
||||||
|
|
||||||
|
# Check for input / help / usage
|
||||||
|
if [ -z "$2" ]
|
||||||
|
then
|
||||||
|
echo "Usage: ./rotate.sh source_folder destination_folder"
|
||||||
|
else
|
||||||
|
|
||||||
# Start logging
|
# Start logging
|
||||||
echo "["$(date)"] - Started Backup"
|
echo "["$(date)"] - Started Backup"
|
||||||
# Check if the destination dir exists. If not create it
|
# Check if the destination dir exists. If not create it
|
||||||
if [ ! -d "$BACKUPDIRDEST/"$(date +"%m-%d-%Y")"/" ]; then
|
if [ ! -d "$BACKUPDIRDEST/"$(date +"%m-%d-%Y")"/" ]; then
|
||||||
# Creates directory for today's backup
|
# Creates directory for today's backup
|
||||||
mkdir $BACKUPDIR/"$(date +"%m-%d-%Y")"
|
mkdir $BACKUPDIRDEST/"$(date +"%m-%d-%Y")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Echo the log line.
|
# Echo the log line.
|
||||||
|
@ -28,8 +35,12 @@ TOTMB=$(du $BACKUPDIRDEST/"$(date +"%m-%d-%Y")"/ -hs)
|
||||||
echo "["$(date)"] - Finished Backup - $TOTMB Copied"
|
echo "["$(date)"] - Finished Backup - $TOTMB Copied"
|
||||||
|
|
||||||
# Search for folders older than NUMDAYS days and remove them. This makes possible rotation of backups
|
# Search for folders older than NUMDAYS days and remove them. This makes possible rotation of backups
|
||||||
|
if [ "$BACKUPDIRDEST" != "" ]; then
|
||||||
for i in `find $BACKUPDIRDEST/ -maxdepth 1 -type d -mtime +$NUMDAYS -print`;
|
for i in `find $BACKUPDIRDEST/ -maxdepth 1 -type d -mtime +$NUMDAYS -print`;
|
||||||
do
|
do
|
||||||
echo -e "["$(date)"] - Found outdated backup folder! Deleting directory $i";
|
echo -e "["$(date)"] - Found backup folder from $(stat -c %y $i)! Deleting directory $i";
|
||||||
\rm -rf $i;
|
#\rm -rf $i;
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user