68 lines
2.5 KiB
Bash
Executable File
68 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
##
|
|
# Copyright (C) 2013-2014 Janek Bevendorff
|
|
# Website: http://www.refining-linux.org/
|
|
#
|
|
# Create daily, weekly or monthly snapshots from manual push backups
|
|
#
|
|
# The MIT License (MIT)
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
# in the Software without restriction, including without limitation the rights
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
# THE SOFTWARE.
|
|
##
|
|
|
|
if [ "$1" == "" ]; then
|
|
. rs-version
|
|
echo "Usage: $(basename $0) <backup level>"
|
|
exit
|
|
fi
|
|
|
|
. /etc/rs-backup/server-config
|
|
|
|
for home_dir in "${BACKUP_ROOT}"/*; do
|
|
if [ -d "${home_dir}/${FILES_DIR}" ] && [ -e "${home_dir}/rsnapshot.conf" ]; then
|
|
# Since we're relying on the client to push changes, there isn't
|
|
# necessarily a new increment pushed yet.
|
|
# Only rotate if there are really new increments to prevent
|
|
# successive backup deletion
|
|
config=$(cat "${BACKUP_ROOT}/etc/rsnapshot.global.conf")
|
|
|
|
# Get number of preceding increments
|
|
config=$(echo "${config}" | awk '$1 == "retain" && $2 == "'${1}'" { print lastline } { lastline = $0 }')
|
|
preceding_name=$(echo "${config}" | awk '{ print $2 }')
|
|
preceding_number=$(($(echo "${config}" | awk ' { print $3 }') - 1))
|
|
|
|
# Continue if no proper preceding increment could be found
|
|
if [ "${preceding_name}" == "" ] ||
|
|
[ ! -d "${home_dir}/${FILES_DIR}/${preceding_name}.${preceding_number}" ]; then
|
|
echo "Not enough preceding increments found, not rotating ${1}"
|
|
continue
|
|
fi
|
|
|
|
cd "${home_dir}/${FILES_DIR}"
|
|
stat_cmd="stat"
|
|
# avoid using BusyBox stat on Synology
|
|
if [ -x /opt/bin/stat ]; then
|
|
stat_cmd="/opt/bin/stat"
|
|
fi
|
|
owner=$(${stat_cmd} -c '%U' .)
|
|
|
|
su - "${owner}" -c "rsnapshot -c '${home_dir}/rsnapshot.conf' '$1'"
|
|
fi
|
|
done
|