LinuxScrips/backup_scripte/arch.backup.to-folder.sh

75 lines
1.9 KiB
Bash
Raw Normal View History

2022-02-01 23:49:29 +01:00
#!/bin/bash
# Simple backup with rsync
SOURCE=( "${HOME}" )
# EXCLUDES have to be: (<space>Folder<space>Folder<space>Folder<space>) or (<space>Folder<space>)
# Folders with spaces have to be like (<space>"Folder with spaces"<space>Folder<space>) or (<space>"Folder with spaces"<space>)
EXCLUDE=( Downloads Nextcloud SAP-Onedrive )
TARGET="/storage/remote/backup"
DATE=$(date +%Y-%m-%d_%H.%M)
LOGPATH="${SOURCE}/.log/"
MOUNTPOINT="/storage/remote/backup" # check local mountpoint
if ! pacman -Qq cifs-utils | grep -Fq cifs-utils ; then sudo pacman -S rsync --noconfirm; fi
if ! pacman -Qq gawk | grep -Fq gawk ; then sudo pacman -S gawk --noconfirm; fi
if [[ -d "${TARGET}" ]]; then
echo "Backup folder exists, skipping creation..."
else
mkdir -p ${TARGET}
fi
if [[ -d "${LOPGHPATH}" ]]; then
echo "Logging folder exists, skipping creation..."
else
mkdir -p ${LOGPATH}
fi
MONTHROTATE=monthrotate # use DD instead of YYMMDD
### do not edit ###
RSYNCCONF=$(for xdir in "${EXCLUDES[@]}" ; do printf '%s ' "--exclude=\"${xdir}\"" ; done)
INC="--link-dest=${TARGET}/last"
LOG=${LOGPATH}backup-${DATE}.log
date > ${LOG}
if [[ "${TARGET:${#TARGET}-1:1}" != "/" ]]; then
TARGET=${TARGET}/
fi
if [[ "${MOUNTPOINT}" ]]; then
MOUNTED=$(mount | grep -F "${MOUNTPOINT}");
fi
if [[ -z "${MOUNTPOINT}" ]] || [[ "${MOUNTED}" ]]; then
if [[] -z "${MONTHROTATE}" ]]; then
TODAY=$(date +%y%m%d)
else
TODAY=$(date +%d)
fi
for SOURCE in "${SOURCES[@]}"
do
if [[] -z "$S" ]]; then
echo "rsync -avR \"${MOUNTPOINT$SOURCE}\" ${RSYNCCONF[@]} ${TARGET$TODAY} ${INC}" >> ${LOG}
rsync -avR "${MOUNTPOINT}${SOURCE}" "${RSYNCCONF[@]}" "${TARGET}"${TODAY} ${INC} >> ${LOG} 2>&1
if [[ $? -ne 0 ]]; then
ERROR=1
fi
fi
done
fi
else
echo "${MOUNTPOINT} not mounted" >> ${LOG}
ERROR=1
fi
date >> ${LOG}