From 7dd4d76a71855d80858016682a28dbaed5ce99d2 Mon Sep 17 00:00:00 2001 From: Rogee Date: Tue, 17 Dec 2024 09:27:24 +0800 Subject: [PATCH] feat: sync datas --- cron.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cron.sh diff --git a/cron.sh b/cron.sh new file mode 100644 index 0000000..00e7706 --- /dev/null +++ b/cron.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +LOG_FILE="/var/log/qvyun.sync.log" +MAX_SIZE=$((10 * 1024 * 1024)) # 10MB in bytes + +# Clean up old log files +find "$(dirname "$LOG_FILE")" -name "$(basename "$LOG_FILE")*" -type f -mtime +7 -delete + +# Check and rotate log if needed +if [ -f "$LOG_FILE" ]; then + FILE_SIZE=$(stat -f%z "$LOG_FILE") + if [ $FILE_SIZE -gt $MAX_SIZE ]; then + mv "$LOG_FILE" "${LOG_FILE}.$(date +%Y%m%d-%H%M%S)" + fi +fi + +start_time=$(date "+%Y-%m-%d %H:%M:%S") +echo "Start sync at $start_time" >>"$LOG_FILE" + +qvyun --config /usr/local/etc/qvyun.toml tasks discover --from /mnt/ypl/publish/ --to /mnt/ypl/publish/processed/1 2>&1 >>"$LOG_FILE" +rsync -avh --progress /mnt/ypl/publish/processed/ server.ali.bj.01:/data 2>&1 >>"$LOG_FILE" + +end_time=$(date "+%Y-%m-%d %H:%M:%S") +echo "End sync at $end_time" >>"$LOG_FILE"