# HG changeset patch # User František Kučera # Date 1555779094 -7200 # Node ID ca71e981bdb4dc7892bac268bf54893236d2af93 # Parent 308978165cc3be960f809356b389ec08ca2dc70e list repositories command diff -r 308978165cc3 -r ca71e981bdb4 vcs-backup.sh --- a/vcs-backup.sh Fri Apr 19 23:26:08 2019 +0200 +++ b/vcs-backup.sh Sat Apr 20 18:51:34 2019 +0200 @@ -24,7 +24,7 @@ VCS_BACKUP_CONFIG_DIR="$VCS_BACKUP_DATA_DIR/config"; VCS_BACKUP_SNAPSHOT_DIR="$VCS_BACKUP_DATA_DIR/snapshot"; VCS_BACKUP_SUBVOLUME_SOCKET="/run/vcs-backup-subvolume"; -VCS_BACKUP_CLONE_SOCKET="/run/vcs-backup-clone/socket"; +VCS_BACKUP_CLONE_SOCKET="/run/vcs-backup-clone/socket"; # the directory will be writable by ${VCS_BACKUP_USER} VCS_BACKUP_CLONE_CALLBACK_SOCKET="clone-callback"; VCS_BACKUP_USER="vcs-backup"; VCS_BACKUP_MANAGER="vcs-backup-manager"; @@ -42,7 +42,6 @@ mkdir "$(dirname VCS_BACKUP_CLONE_SOCKET)" chown "${VCS_BACKUP_USER}:${VCS_BACKUP_USER}" "$(dirname VCS_BACKUP_CLONE_SOCKET)" -chown "${VCS_BACKUP_USER}:${VCS_BACKUP_USER}" "$VCS_BACKUP_CURRENT_DIR" chown "${VCS_BACKUP_MANAGER}:${VCS_BACKUP_MANAGER}" "$VCS_BACKUP_CONFIG_DIR" } @@ -154,6 +153,44 @@ done } +# Environment: client +# prints list of repositories in recfile format +# usage example: vcs-backup.sh clientListRepositories | relpipe-in-recfile | relpipe-out-tabular +vcs_backup_public_clientListRepositories() { + loadConfigFile ~/.config/vcs-backup/client.cfg; + ${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverListRepositories; +} + +# Environment: server +# User: $VCS_BACKUP_MANAGER +vcs_backup_public_serverListRepositories() { + echo "%rec: repositories"; + echo "%type: bytes int"; + echo "%type: public bool"; + echo; + + find "$VCS_BACKUP_CONFIG_DIR" -name url.txt -printf '%P\n' | sort | xargs dirname | while read d; do + url=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/url.txt"); + state=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/state.txt"); + vcsType=$(echo "$d" | sed 's@/.*@@g'); + sizeBytes=$(du -sb "$VCS_BACKUP_CURRENT_DIR/$d" | cut -f1); + [[ -e "$VCS_BACKUP_PUBLIC_DIR/$d" ]] && public="true" || public="false"; + + if [[ "$vcsType" == "hg" ]]; then lastCommit=$(hg log --limit 1 --template '{date|isodatesec}' -R "$VCS_BACKUP_CURRENT_DIR/$d" 2>/dev/null); + elif [[ "$vcsType" == "git" ]]; then lastCommit=$(git -C "$VCS_BACKUP_CURRENT_DIR/$d" log --max-count=1 --pretty="%ai"); + else lastCommit=""; fi + + echo "type: $vcsType"; + echo "url: $url"; + echo "state: $state"; + echo "public: $public"; + echo "serverPath: $VCS_BACKUP_CURRENT_DIR/$d"; + echo "size: $sizeBytes"; + echo "lastCommit: $lastCommit"; + echo; + done +} + # Environment: server # User: $VCS_BACKUP_USER # should be called from cron (usually every day)