# HG changeset patch # User František Kučera # Date 1555797919 -7200 # Node ID d46ed3f5c72b9dcfe7a7e44b6c0e59dfc90ca4a8 # Parent 5454e8a0c53edf1778da6b4a4e112b0fb019541c pull cron task diff -r 5454e8a0c53e -r d46ed3f5c72b vcs-backup.sh --- a/vcs-backup.sh Sat Apr 20 22:24:24 2019 +0200 +++ b/vcs-backup.sh Sun Apr 21 00:05:19 2019 +0200 @@ -205,11 +205,47 @@ # User: $VCS_BACKUP_USER # should be called from cron (usually every day) vcs_backup_public_serverPullCronTask() { - return; + echo "%rec: pull"; + echo "%type: started date"; + echo "%type: finished date"; + echo "%type: duration int"; + echo "%type: resultCode int"; + + find "$VCS_BACKUP_CONFIG_DIR" -name url.txt -printf '%P\n' | sort | xargs dirname | while read d; do + state=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/state.txt"); + vcsType=$(echo "$d" | sed 's@/.*@@g'); + absolutePath="$VCS_BACKUP_CURRENT_DIR/$d"; + + + pullStarted=$(date --iso-8601=s); + pullStartedMiliseconds=$(($(date +%s%N)/1000000)); + pullFinished=""; + pullDuration=""; + pullResult=""; + pullResultCode=""; + if [[ "$state" == "cloned" ]]; then + if [[ "$vcsType" == "hg" ]]; then pullResult=$(hg pull --force --repository "$absolutePath" 2>&1); pullResultCode=$?; + elif [[ "$vcsType" == "git" ]]; then pullResult=$(git -C "$absolutePath" fetch 2>&1); pullResultCode=$?; + fi + pullFinished=$(date --iso-8601=s); + pullFinishedMiliseconds=$(($(date +%s%N)/1000000)); + pullDuration=$(( $pullFinishedMiliseconds - $pullStartedMiliseconds )); + fi + + printRecfileKeyValue "serverPath" "$absolutePath"; + printRecfileKeyValue "type" "$vcsType"; + printRecfileKeyValue "state" "$state"; + printRecfileKeyValue "started" "$pullStarted"; + printRecfileKeyValue "finished" "$pullFinished"; + printRecfileKeyValue "duration" "$pullDuration"; + printRecfileKeyValue "resultCode" "$pullResultCode"; + printRecfileKeyValue "message" "$pullResult"; + echo; + done } # Environment: server -# User: $VCS_BACKUP_USER +# User: root # should be called from cron (usually every day) after Pull (see above) vcs_backup_public_serverSnapshotCronTask() { return;