# HG changeset patch # User František Kučera # Date 1555925083 -7200 # Node ID e7279b13a071d58b8e7f88a2697bad8e41a3e331 # Parent 1e1ba6753d9252c5eb2cf87810a1dfa9707601b4 snapshot cron task diff -r 1e1ba6753d92 -r e7279b13a071 vcs-backup.sh --- a/vcs-backup.sh Sun Apr 21 21:57:46 2019 +0200 +++ b/vcs-backup.sh Mon Apr 22 11:24:43 2019 +0200 @@ -118,6 +118,7 @@ loadConfigFile "/etc/vcs-backup/server.cfg"; relativePath=$1/$(urlToRelativeDirectoryPath "$2"); absolutePath="$VCS_BACKUP_CONFIG_DIR/$relativePath"; + # TODO: stop if directory already exists / only add public link? mkdir -p "$absolutePath"; echo "$2" > "$absolutePath/url.txt" echo "submited" > "$absolutePath/state.txt" @@ -206,7 +207,7 @@ # Environment: server # User: $VCS_BACKUP_MANAGER vcs_backup_public_serverListRepositories() { - printRecfileKeyValue "%rec" "repositories"; + printRecfileKeyValue "%rec" "repository"; printRecfileKeyValue "%type" "bytes int"; printRecfileKeyValue "%type" "public bool"; echo; @@ -248,7 +249,6 @@ vcsType=$(echo "$d" | sed 's@/.*@@g'); absolutePath="$VCS_BACKUP_CURRENT_DIR/$d"; - pullStarted=$(date --iso-8601=s); pullStartedMiliseconds=$(($(date +%s%N)/1000000)); pullFinished=""; @@ -280,7 +280,45 @@ # User: root # should be called from cron (usually every day) after Pull (see above) vcs_backup_public_serverSnapshotCronTask() { - return; + printRecfileKeyValue "%rec" "snapshot"; + printRecfileKeyValue "%type" "started date"; + printRecfileKeyValue "%type" "finished date"; + printRecfileKeyValue "%type" "duration int"; + printRecfileKeyValue "%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"; + + started=$(date --iso-8601=s); + startedMiliseconds=$(($(date +%s%N)/1000000)); + finished=""; + duration=""; + result=""; + resultCode=""; + snapshotPath=""; + if [[ "$state" == "cloned" ]]; then + snapshotPath="$VCS_BACKUP_SNAPSHOT_DIR/$d/$(date --iso-8601=date)"; + mkdir -p $(dirname "$snapshotPath"); + result=$(btrfs subvolume snapshot -r "$absolutePath" "$snapshotPath" 2>&1); + resultCode=$?; + finished=$(date --iso-8601=s); + finishedMiliseconds=$(($(date +%s%N)/1000000)); + duration=$(( $finishedMiliseconds - $startedMiliseconds )); + fi + + printRecfileKeyValue "currentPath" "$absolutePath"; + printRecfileKeyValue "snapshotPath" "$snapshotPath"; + printRecfileKeyValue "type" "$vcsType"; + printRecfileKeyValue "state" "$state"; + printRecfileKeyValue "started" "$started"; + printRecfileKeyValue "finished" "$finished"; + printRecfileKeyValue "duration" "$duration"; + printRecfileKeyValue "resultCode" "$resultCode"; + printRecfileKeyValue "message" "$result"; + echo; + done } # --- Single entry-point: --------------------------------------------------------------------------