1.1 --- a/vcs-backup.sh Fri Apr 19 23:26:08 2019 +0200
1.2 +++ b/vcs-backup.sh Sat Apr 20 18:51:34 2019 +0200
1.3 @@ -24,7 +24,7 @@
1.4 VCS_BACKUP_CONFIG_DIR="$VCS_BACKUP_DATA_DIR/config";
1.5 VCS_BACKUP_SNAPSHOT_DIR="$VCS_BACKUP_DATA_DIR/snapshot";
1.6 VCS_BACKUP_SUBVOLUME_SOCKET="/run/vcs-backup-subvolume";
1.7 -VCS_BACKUP_CLONE_SOCKET="/run/vcs-backup-clone/socket";
1.8 +VCS_BACKUP_CLONE_SOCKET="/run/vcs-backup-clone/socket"; # the directory will be writable by ${VCS_BACKUP_USER}
1.9 VCS_BACKUP_CLONE_CALLBACK_SOCKET="clone-callback";
1.10 VCS_BACKUP_USER="vcs-backup";
1.11 VCS_BACKUP_MANAGER="vcs-backup-manager";
1.12 @@ -42,7 +42,6 @@
1.13 mkdir "$(dirname VCS_BACKUP_CLONE_SOCKET)"
1.14
1.15 chown "${VCS_BACKUP_USER}:${VCS_BACKUP_USER}" "$(dirname VCS_BACKUP_CLONE_SOCKET)"
1.16 -chown "${VCS_BACKUP_USER}:${VCS_BACKUP_USER}" "$VCS_BACKUP_CURRENT_DIR"
1.17 chown "${VCS_BACKUP_MANAGER}:${VCS_BACKUP_MANAGER}" "$VCS_BACKUP_CONFIG_DIR"
1.18 }
1.19
1.20 @@ -154,6 +153,44 @@
1.21 done
1.22 }
1.23
1.24 +# Environment: client
1.25 +# prints list of repositories in recfile format
1.26 +# usage example: vcs-backup.sh clientListRepositories | relpipe-in-recfile | relpipe-out-tabular
1.27 +vcs_backup_public_clientListRepositories() {
1.28 + loadConfigFile ~/.config/vcs-backup/client.cfg;
1.29 + ${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverListRepositories;
1.30 +}
1.31 +
1.32 +# Environment: server
1.33 +# User: $VCS_BACKUP_MANAGER
1.34 +vcs_backup_public_serverListRepositories() {
1.35 + echo "%rec: repositories";
1.36 + echo "%type: bytes int";
1.37 + echo "%type: public bool";
1.38 + echo;
1.39 +
1.40 + find "$VCS_BACKUP_CONFIG_DIR" -name url.txt -printf '%P\n' | sort | xargs dirname | while read d; do
1.41 + url=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/url.txt");
1.42 + state=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/state.txt");
1.43 + vcsType=$(echo "$d" | sed 's@/.*@@g');
1.44 + sizeBytes=$(du -sb "$VCS_BACKUP_CURRENT_DIR/$d" | cut -f1);
1.45 + [[ -e "$VCS_BACKUP_PUBLIC_DIR/$d" ]] && public="true" || public="false";
1.46 +
1.47 + if [[ "$vcsType" == "hg" ]]; then lastCommit=$(hg log --limit 1 --template '{date|isodatesec}' -R "$VCS_BACKUP_CURRENT_DIR/$d" 2>/dev/null);
1.48 + elif [[ "$vcsType" == "git" ]]; then lastCommit=$(git -C "$VCS_BACKUP_CURRENT_DIR/$d" log --max-count=1 --pretty="%ai");
1.49 + else lastCommit=""; fi
1.50 +
1.51 + echo "type: $vcsType";
1.52 + echo "url: $url";
1.53 + echo "state: $state";
1.54 + echo "public: $public";
1.55 + echo "serverPath: $VCS_BACKUP_CURRENT_DIR/$d";
1.56 + echo "size: $sizeBytes";
1.57 + echo "lastCommit: $lastCommit";
1.58 + echo;
1.59 + done
1.60 +}
1.61 +
1.62 # Environment: server
1.63 # User: $VCS_BACKUP_USER
1.64 # should be called from cron (usually every day)