vcs-backup.sh
branchv_0
changeset 11 d46ed3f5c72b
parent 10 5454e8a0c53e
child 12 7bdf24cc2e9e
     1.1 --- a/vcs-backup.sh	Sat Apr 20 22:24:24 2019 +0200
     1.2 +++ b/vcs-backup.sh	Sun Apr 21 00:05:19 2019 +0200
     1.3 @@ -205,11 +205,47 @@
     1.4  # User: $VCS_BACKUP_USER
     1.5  # should be called from cron (usually every day)
     1.6  vcs_backup_public_serverPullCronTask() {
     1.7 -	return;
     1.8 +	echo "%rec: pull";
     1.9 +	echo "%type: started date";
    1.10 +	echo "%type: finished date";
    1.11 +	echo "%type: duration int";
    1.12 +	echo "%type: resultCode int";
    1.13 +
    1.14 +	find "$VCS_BACKUP_CONFIG_DIR" -name url.txt -printf '%P\n' | sort | xargs dirname | while read d; do
    1.15 +		state=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/state.txt");
    1.16 +		vcsType=$(echo "$d" | sed 's@/.*@@g');
    1.17 +		absolutePath="$VCS_BACKUP_CURRENT_DIR/$d";
    1.18 +
    1.19 +
    1.20 +		pullStarted=$(date --iso-8601=s);
    1.21 +		pullStartedMiliseconds=$(($(date +%s%N)/1000000));
    1.22 +		pullFinished="";
    1.23 +		pullDuration="";
    1.24 +		pullResult="";
    1.25 +		pullResultCode="";
    1.26 +		if [[ "$state" == "cloned" ]]; then
    1.27 +			if   [[ "$vcsType" == "hg" ]];  then pullResult=$(hg pull --force --repository "$absolutePath" 2>&1); pullResultCode=$?;
    1.28 +			elif [[ "$vcsType" == "git" ]]; then pullResult=$(git -C "$absolutePath" fetch 2>&1); pullResultCode=$?;
    1.29 +			fi
    1.30 +			pullFinished=$(date --iso-8601=s);
    1.31 +			pullFinishedMiliseconds=$(($(date +%s%N)/1000000));
    1.32 +			pullDuration=$(( $pullFinishedMiliseconds - $pullStartedMiliseconds ));
    1.33 +		fi
    1.34 +
    1.35 +		printRecfileKeyValue "serverPath"      "$absolutePath";
    1.36 +		printRecfileKeyValue "type"            "$vcsType";
    1.37 +		printRecfileKeyValue "state"           "$state";
    1.38 +		printRecfileKeyValue "started"         "$pullStarted";
    1.39 +		printRecfileKeyValue "finished"        "$pullFinished";
    1.40 +		printRecfileKeyValue "duration"        "$pullDuration";
    1.41 +		printRecfileKeyValue "resultCode"      "$pullResultCode";
    1.42 +		printRecfileKeyValue "message"         "$pullResult";
    1.43 +		echo;
    1.44 +	done
    1.45  }
    1.46  
    1.47  # Environment: server
    1.48 -# User: $VCS_BACKUP_USER
    1.49 +# User: root
    1.50  # should be called from cron (usually every day) after Pull (see above)
    1.51  vcs_backup_public_serverSnapshotCronTask() {
    1.52  	return;