2021-11-02 08:05:23 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
ABSOLUTE_FILENAME=`readlink -e "$0"`
|
|
|
|
|
DIRECTORY=`dirname "$ABSOLUTE_FILENAME"`
|
|
|
|
|
|
|
|
|
|
source ${DIRECTORY}/config
|
|
|
|
|
|
2021-12-12 11:19:30 +00:00
|
|
|
|
stamp=`date +%s`-`date +"%Y%m%d-%H%M%S-I"`
|
2021-11-02 08:05:23 +00:00
|
|
|
|
do_full=""
|
|
|
|
|
do_quet=0
|
|
|
|
|
|
|
|
|
|
while getopts "fq" opt; do
|
|
|
|
|
case $opt in
|
|
|
|
|
f) do_full=1;;
|
|
|
|
|
q) do_quet=1;;
|
|
|
|
|
# -f -full
|
|
|
|
|
# -q -quet (no verbose output)
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ -n "${do_full}" ]
|
|
|
|
|
then
|
|
|
|
|
if [ "${do_quet}" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Full backup started"
|
|
|
|
|
fi
|
|
|
|
|
|
2021-12-12 11:19:30 +00:00
|
|
|
|
stamp=`date +%s`-`date +"%Y%m%d-%H%M%S-F"`
|
2021-11-02 08:05:23 +00:00
|
|
|
|
rm -f ${prefix}/incremental/*
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ ! -d "${prefix}/incremental" ]; then
|
|
|
|
|
# Создать папку, только если ее не было
|
|
|
|
|
mkdir ${prefix}/incremental
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ ! -d "${prefix}/compressed" ]; then
|
|
|
|
|
# Создать папку, только если ее не было
|
|
|
|
|
mkdir ${prefix}/compressed
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
mkdir ${prefix}/${stamp}
|
|
|
|
|
|
|
|
|
|
# SQL DB Backup
|
|
|
|
|
for sql_item in ${sql_list}
|
|
|
|
|
do
|
|
|
|
|
if [ "${do_quet}" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo -n "Collecting database ${sql_item//:/ }...."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
#${sqldump_prefix} ${sql_item//:/ } | gzip > ${prefix}/${stamp}/${sql_item//:/.}.sql.gz
|
|
|
|
|
|
|
|
|
|
if [[ -f "${prefix}/incremental/${sql_item//:/.}.sql" ]]
|
|
|
|
|
then
|
|
|
|
|
xsuffix=".diff"
|
2023-06-21 08:11:54 +00:00
|
|
|
|
${sqldump_prefix} ${sql_item//:/ } | rdiff delta ${prefix}/incremental/${sql_item//:/.}.sql.sign > ${prefix}/${stamp}/${sql_item//:/.}.sql.delta
|
2021-11-02 08:05:23 +00:00
|
|
|
|
else
|
|
|
|
|
${sqldump_prefix} ${sql_item//:/ } | cat > ${prefix}/${stamp}/${sql_item//:/.}.sql
|
2023-06-21 08:11:54 +00:00
|
|
|
|
rdiff signature ${prefix}/${stamp}/${sql_item//:/.}.sql > ${prefix}/incremental/${sql_item//:/.}.sql.sign
|
2021-11-02 08:05:23 +00:00
|
|
|
|
fi
|
|
|
|
|
if [ "${do_quet}" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "OK"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
#Archiving SQL for DIFF
|
|
|
|
|
|
|
|
|
|
#Files Full Backup
|
|
|
|
|
for file_item in ${files_list}
|
|
|
|
|
do
|
|
|
|
|
xfolder=`echo ${file_item} | awk -F : '{ print $1 }'`
|
|
|
|
|
if [[ -n "`echo ${file_item} | awk -F : '{ print $2 }'`" ]]
|
|
|
|
|
then
|
|
|
|
|
xsubfolders=`echo ${file_item} | sed -e 's/^[^:]*://'`
|
|
|
|
|
else
|
|
|
|
|
xsubfolders="*"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "${do_quet}" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo -n "Collecting folder ${xfolder}...."
|
|
|
|
|
fi
|
|
|
|
|
if [[ -f "${prefix}/incremental/${xfolder////_}.snar" ]]
|
|
|
|
|
then
|
|
|
|
|
cp ${prefix}/incremental/${xfolder////_}.snar ${prefix}/incremental/${xfolder////_}.snar.diff
|
|
|
|
|
xsuffix=".diff"
|
|
|
|
|
else
|
|
|
|
|
xsuffix=""
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cd ${xfolder} && tar -c --listed-incremental=${prefix}/incremental/${xfolder////_}.snar${xsuffix} -f ${prefix}/${stamp}/${xfolder////_}${xsuffix}.tar ${xsubfolders//:/ }
|
|
|
|
|
rm -f ${prefix}/incremental/${xfolder////_}.snar.diff
|
|
|
|
|
if [ "${do_quet}" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "OK"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Compressing
|
2022-06-05 12:15:39 +00:00
|
|
|
|
|
|
|
|
|
if [ "${do_quet}" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Compressing"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
find ${prefix}/${stamp} -maxdepth 1 -type f -not -name "*.gz" -exec gzip {} \;
|
|
|
|
|
|
|
|
|
|
# Encrypting
|
|
|
|
|
if [ -n "${gpg_passphrase}" ]
|
|
|
|
|
then
|
|
|
|
|
if [ "${do_quet}" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Encrypting"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
find ${prefix}/${stamp} -maxdepth 1 -type f -exec bash -c "echo \"${gpg_passphrase}\" | gpg --batch --passphrase-fd 0 --symmetric \"{}\" && rm -f \"{}\"" \;
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "${do_quet}" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Packing"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Packing
|
|
|
|
|
cd ${prefix}/${stamp} && tar -cf ${prefix}/compressed/${stamp}.tar *
|
2021-11-02 08:05:23 +00:00
|
|
|
|
rm -f $prefix/$stamp/*
|
|
|
|
|
rmdir $prefix/$stamp
|
|
|
|
|
|
2022-06-05 12:15:39 +00:00
|
|
|
|
|
2021-11-02 08:05:23 +00:00
|
|
|
|
# Sending data
|
2021-11-02 09:10:54 +00:00
|
|
|
|
if [ -n "${sshhost}" ]
|
|
|
|
|
then
|
|
|
|
|
for xfile_item in `ls ${prefix}/compressed`
|
|
|
|
|
do
|
2022-06-05 21:42:57 +00:00
|
|
|
|
if [ "${do_quet}" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Sending via SSH $xfile_item"
|
|
|
|
|
fi
|
|
|
|
|
scp -B -P ${sshport} -i ${sshkey} ${prefix}/compressed/${xfile_item} ${sshuser}@${sshhost}:${sshpath} > /dev/null
|
2021-11-02 09:10:54 +00:00
|
|
|
|
if [ "$?" == 0 ]
|
|
|
|
|
then
|
|
|
|
|
rm -f ${prefix}/compressed/${xfile_item}
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
2021-11-02 08:05:23 +00:00
|
|
|
|
|