#!/bin/bash

echo "========================================================================="
echo Start Time: `date`
set -x

cp -rf /var/spool/cron/crontabs/ /opt/configs/
cp -rf /usr/local/nginx/conf/nginx.conf /opt/configs/nginx/nginx.conf
cp -rf /usr/local/nginx/conf/domain_confs/ /opt/configs/nginx/
cp -rf /etc/docker/daemon.json /opt/configs/conf/
cp -rf /etc/sysctl.conf /opt/configs/conf/
cp -rf /etc/pip.conf /opt/configs/conf/
cp -rf /etc/apt/sources.list /opt/configs/conf/
cp -rf /root/.acme.sh/*ecc /opt/configs/acme/

cd /opt && t=`date +%Y%m%dT%H%M%S`
rsync -av --delete apps configs logs scripts websites wd/72-Backups/CrossChain/VPS/ > /opt/logs/rsync/rsync_${t}.log
cd /opt/logs/rsync/
let count=`ls | wc -l`
if [[ $count -gt 10 ]]; then
    rsync_logs=()
    for((i=1;i<=$count;i++)); do
        rsync_logs[$i]=`ls | sort -r | head -n $i | tail -1`
    done

    for i in `seq 11 $count`; do
        rm -rf ${rsync_logs[$i]}
    done
fi

# tar -I pixz -cf $backup_dir/vps-${t}.tar.xz -C /opt configs data logs scripts source-code websites > /dev/null 2>&1
set +x
echo End   Time: `date`
echo "========================================================================="
echo
echo

