mirror of
https://github.com/brunofontes/linuxShortcuts.git
synced 2024-11-24 00:50:51 +00:00
fix(backup): Each backup has it's own folder
I was previously using one folder for multiple backups, but it doesn't help for pruning old backups. So, now, each backup set has it's own folder, what makes it easier to restore as well.
This commit is contained in:
parent
d3fc0cecb6
commit
fbb551377b
@ -1,36 +1,60 @@
|
|||||||
|
# Ansi color code variables
|
||||||
|
red="\e[0;91m"
|
||||||
|
blue="\e[0;94m"
|
||||||
|
expand_bg="\e[K"
|
||||||
|
blue_bg="\e[0;104m${expand_bg}"
|
||||||
|
red_bg="\e[0;101m${expand_bg}"
|
||||||
|
green_bg="\e[0;102m${expand_bg}"
|
||||||
|
green="\e[0;92m"
|
||||||
|
white="\e[0;97m"
|
||||||
|
bold="\e[1m"
|
||||||
|
uline="\e[4m"
|
||||||
|
reset="\e[0m"
|
||||||
|
|
||||||
function backup () {
|
function backup () {
|
||||||
# $1 - Repository
|
# $1 - Repository
|
||||||
# $2-$N - Files/Folders to backup
|
# $2 - Backup name
|
||||||
|
# $3 - Files/Folders to backup
|
||||||
#--stats = show stats at end
|
prepareFolder $1
|
||||||
#--progress = show each file being processed
|
echo -e "${blue} `date +%r` - Backing up (compressed)...${reset}"
|
||||||
nice -n 19 borg create --compression auto,zstd,9 --exclude-from=./exclude $1 "$2"
|
nice -n 19 borg create --compression auto,zstd,9 --exclude-from=./exclude "$1::$2" "$3"
|
||||||
|
checkBackup $1
|
||||||
}
|
}
|
||||||
|
|
||||||
function backupNoCompression () {
|
function backupNoCompression () {
|
||||||
# $1 - Repository
|
# $1 - Repository
|
||||||
# $2-$N - Files/Folders to backup
|
# $2 - Backup name
|
||||||
|
# $3 - Files/Folders to backup
|
||||||
|
prepareFolder $1
|
||||||
|
echo -e "${blue} `date +%r` - Backing up (uncompressed)...${reset}"
|
||||||
|
nice -n 19 borg create --compression none --exclude-from=./exclude "$1::$2" "$3"
|
||||||
|
checkBackup $1
|
||||||
|
}
|
||||||
|
|
||||||
#--stats = show stats at end
|
function prepareFolder() {
|
||||||
#--progress = show each file being processed
|
if [ ! -d "$1" ]; then
|
||||||
nice -n 19 borg create --compression none --exclude-from=./exclude $1 "$2"
|
mkdir -p "$1"
|
||||||
|
borg init --encryption=none $1
|
||||||
|
else
|
||||||
|
pruneBackup $1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBackup() {
|
function checkBackup() {
|
||||||
echo -n "`date +%r`- Checking the backup..."
|
echo -e -n "${blue} `date +%r` - Checking the backup...${reset}"
|
||||||
borg check "$1" > "$1"_status
|
borg check "$1" > "$1"_status
|
||||||
if [[ $(cat "$1"_status) != "" ]]; then
|
if [[ $(cat "$1"_status) != "" ]]; then
|
||||||
echo -e "\n\033[1;31m ERROR UNPACKING $1 \033[0m"
|
echo -e "\n\033[1;31m ERROR UNPACKING $1 \033[0m"
|
||||||
else
|
else
|
||||||
echo ".OK!"
|
echo -e ".${green}OK!${reset}"
|
||||||
rm "$1"_status
|
rm "$1"_status
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
function pruneBackup() {
|
function pruneBackup() {
|
||||||
echo -e "\e[97m`date +%r` - Prune old backups...\e[39m"
|
echo -e "${blue} `date +%r` - Prune old backups...${reset}"
|
||||||
borg prune -v --list --dry-run --keep-weekly=8 --keep-monthly=12 --keep-yearly=3 $1
|
borg prune --keep-within=1y --keep-daily=30 --keep-weekly=12 --keep-monthly=24 --keep-yearly=3 $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -48,12 +72,10 @@ HDPath="/run/media/bruno/Backup_$ActiveDisk"
|
|||||||
|
|
||||||
BACKUPPATH="$HDPath/Backup"
|
BACKUPPATH="$HDPath/Backup"
|
||||||
YEARMONTH=`date +%Y-%m-%d`
|
YEARMONTH=`date +%Y-%m-%d`
|
||||||
HDYEARMONTH="$BACKUPPATH::$YEARMONTH"
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Disk : $ActiveDisk"
|
echo "Disk : $ActiveDisk"
|
||||||
echo "HD Backup path : $BACKUPPATH"
|
echo "HD Backup path : $BACKUPPATH"
|
||||||
echo "HD Year-Month path: $HDYEARMONTH"
|
|
||||||
echo
|
echo
|
||||||
echo "Please, insert Disk #$ActiveDisk and press enter to start backup"
|
echo "Please, insert Disk #$ActiveDisk and press enter to start backup"
|
||||||
read
|
read
|
||||||
@ -71,50 +93,36 @@ done
|
|||||||
|
|
||||||
# If folder does not exist, exit with error
|
# If folder does not exist, exit with error
|
||||||
[ ! -d "$HDPath" ] && echo "This disk was used last time. Please, plug Backup_$ActiveDisk before running this script." && read && exit 1
|
[ ! -d "$HDPath" ] && echo "This disk was used last time. Please, plug Backup_$ActiveDisk before running this script." && read && exit 1
|
||||||
echo ".OK!"
|
echo -e ".${green}OK!${reset}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
if [ ! -d "$BACKUPPATH" ]; then
|
echo -e "${white}`date +%r` - Copying Linux Home folder (1/7)...\e[39m"
|
||||||
mkdir -p "$BACKUPPATH"
|
echo -e "${white} `date +%r` - Bruno\e[39m"
|
||||||
borg init --encryption=none $BACKUPPATH
|
backup "$HDPath/LinuxHome-Bruno" "$YEARMONTH" "/home/bruno/" || echo ""
|
||||||
|
|
||||||
#Prune old backups
|
echo -e "${white} `date +%r` - Admin\e[39m"
|
||||||
pruneBackup $BACKUPPATH
|
backup "$HDPath/LinuxHome-Admin" "$YEARMONTH" "/home/admin/" || echo ""
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "\e[97m`date +%r` - Copying Linux Home folder (1/7)...\e[39m"
|
echo -e "${white}`date +%r` - Copying Localização folder (2/7)...\e[39m"
|
||||||
echo -e "\e[97m `date +%r` - Bruno\e[39m"
|
backup "$HDPath/Multimedia-Localizacao" "$YEARMONTH" "/run/media/bruno/Multimedia/Localização/" || echo ""
|
||||||
backup "$HDYEARMONTH-LinuxHome-bruno" "/home/bruno/" || echo ""
|
|
||||||
|
|
||||||
echo -e "\e[97m `date +%r` - Admin\e[39m"
|
echo -e "${white}`date +%r` - Copying My Documents folder (3/7)...\e[39m"
|
||||||
backup "$HDYEARMONTH-LinuxHome-admin" "/home/admin/" || echo ""
|
backup "$HDPath/Multimedia-MyDocuments" "$YEARMONTH" "/run/media/bruno/Multimedia/MyDocuments/" || echo ""
|
||||||
|
|
||||||
echo -e "\e[97m`date +%r` - Copying Localização folder (2/7)...\e[39m"
|
echo -e "${white}`date +%r` - Copying Música folder (4/7)...\e[39m"
|
||||||
backup "$HDYEARMONTH-Multimedia-localizacao" "/run/media/bruno/Multimedia/Localização/" || echo ""
|
backup "$HDPath/Multimedia-Musica" "$YEARMONTH" "/run/media/bruno/Multimedia/Música/" || echo ""
|
||||||
|
|
||||||
echo -e "\e[97m`date +%r` - Copying My Documents folder (3/7)...\e[39m"
|
echo -e "${white}`date +%r` - Copying Fotos folder (5/7)...\e[39m"
|
||||||
backup "$HDYEARMONTH-Multimedia-MyDocuments" "/run/media/bruno/Multimedia/MyDocuments/" || echo ""
|
backupNoCompression "$HDPath/Fotos" "$YEARMONTH" "/run/media/bruno/Multimedia/Fotos" || echo ""
|
||||||
|
|
||||||
echo -e "\e[97m`date +%r` - Copying Música folder (4/7)...\e[39m"
|
echo -e "${white}`date +%r` - Copying Video folder (6/7)...\e[39m"
|
||||||
backup "$HDYEARMONTH-Multimedia-musica" "/run/media/bruno/Multimedia/Música/" || echo ""
|
backupNoCompression "$HDPath/Videos" "$YEARMONTH" "/run/media/bruno/Multimedia/Videos" || echo ""
|
||||||
|
|
||||||
checkBackup "$BACKUPPATH"
|
echo -e "${white}`date +%r` - Copying Virtual Machines folder (7/7)...\e[39m"
|
||||||
|
backup "$HDPath/VirtualMachines" "$YEARMONTH" "/run/media/bruno/Multimedia/Virtual Machines" || echo ""
|
||||||
# Rsync Fotos e VMs
|
|
||||||
echo -e "\e[97m`date +%r` - Copying Fotos folder (5/7)...\e[39m"
|
|
||||||
backupNoCompression "$HDPath/Fotos::$YEARMONTH" "/run/media/bruno/Multimedia/Fotos" || echo ""
|
|
||||||
checkBackup "$HDPath/Fotos/"
|
|
||||||
|
|
||||||
echo -e "\e[97m`date +%r` - Copying Video folder (6/7)...\e[39m"
|
|
||||||
backupNoCompression "$HDPath/Videos::$YEARMONTH" "/run/media/bruno/Multimedia/Videos" || echo ""
|
|
||||||
checkBackup "$HDPath/Videos/"
|
|
||||||
|
|
||||||
echo -e "\e[97m`date +%r` - Copying Virtual Machines folder (7/7)...\e[39m"
|
|
||||||
backup "$HDPath/VirtualMachines::$YEARMONTH" "/run/media/bruno/Multimedia/Virtual Machines" || echo ""
|
|
||||||
checkBackup "$HDPath/VirtualMachines/"
|
|
||||||
|
|
||||||
# Show result
|
# Show result
|
||||||
echo -e "\e[97m`date +%r` - Backup finished. Please, verify your log files.\e[39m"
|
echo -e "${green}`date +%r` - Backup finished. Please, verify your log files.\e[39m"
|
||||||
|
|
||||||
echo "$ActiveDisk" > .lastDisk
|
echo "$ActiveDisk" > .lastDisk
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user