Browse Source

remove logrun again because of errors

master
mxmehl 5 years ago
parent
commit
bbd9f67021
  1. 1
      .gitignore
  2. 15
      uberspace-backup.sh

1
.gitignore vendored

@ -1,2 +1,3 @@ @@ -1,2 +1,3 @@
config.cfg
hosts.csv
backup.log

15
uberspace-backup.sh

@ -8,7 +8,7 @@ if [ ! -e "$HOSTS" ]; then echo "Missing hosts file. Please set a correct value @@ -8,7 +8,7 @@ if [ ! -e "$HOSTS" ]; then echo "Missing hosts file. Please set a correct value
# Get current date
DATE=$(date +"%Y-%m-%d_%H-%M")
LOG="$CURDIR"/uberspace-backup.log
LOG="$CURDIR"/backup.log
function trim {
sed -r -e 's/^\s*//g' -e 's/\s*$//g'
@ -17,11 +17,6 @@ function pdate { @@ -17,11 +17,6 @@ function pdate {
DATE=$(date +%y-%m-%d_%H:%M:%S)
echo "[$DATE]"
}
function logrun {
# Write command itself to log, and pipe errors to log
echo "$(pdate) $@" >> "$LOG"
eval "$@" 2>> "$LOG"
}
function logecho {
# Echo string and copy it to log while attaching the current date
echo "$(pdate) $@"
@ -66,19 +61,19 @@ while read line; do @@ -66,19 +61,19 @@ while read line; do
logecho "${RHOST}: Downloading ${SOURCE} to ${DEST}"
# RSYNC
logrun rsync -az -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${RHOST}:${SOURCE}/ "${DEST}"/
rsync -az -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" ${RHOST}:${SOURCE}/ "${DEST}"/
# Pack backup directory, and delete uncompressed one
tar cf ${DEST}.tar ${DEST} # TODO: avoid absolute paths
tar cf ${DEST}.tar -C $(echo ${DEST} | sed "s|$(basename ${DEST})$||") $(basename ${DEST}) # TODO: avoid absolute paths
rm -rf ${DEST}
# Encrypt archive with GPG (it compresses at the same time)
logrun gpg --output ${DEST}.tar.gpg --encrypt --recipient ${GPG} ${DEST}.tar
gpg --output ${DEST}.tar.gpg --encrypt --recipient ${GPG} ${DEST}.tar
rm ${DEST}.tar
# Delete all old directories except the $MAXBAK most recent
if [ $(ls -tp "${BACKUPDIR}"/"${RHOST}"/ | grep '/$' | wc -l) -gt $MAXBAK ]; then
ls -tpd "${BACKUPDIR}"/"${RHOST}"/* | grep '/$' | tail -n +$[$MAXBAK + 1] | xargs -d '\n' rm -rv --
ls -tpd "${BACKUPDIR}"/"${RHOST}"/* | grep '/$' | tail -n +$[$MAXBAK + 1] | xargs -d '\n' rm -r --
fi
done

Loading…
Cancel
Save