snapshot cron task v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 22 Apr 2019 11:24:43 +0200
branchv_0
changeset 15e7279b13a071
parent 14 1e1ba6753d92
child 16 44a8a36ca380
snapshot cron task
vcs-backup.sh
     1.1 --- a/vcs-backup.sh	Sun Apr 21 21:57:46 2019 +0200
     1.2 +++ b/vcs-backup.sh	Mon Apr 22 11:24:43 2019 +0200
     1.3 @@ -118,6 +118,7 @@
     1.4  		loadConfigFile "/etc/vcs-backup/server.cfg";
     1.5  		relativePath=$1/$(urlToRelativeDirectoryPath "$2");
     1.6  		absolutePath="$VCS_BACKUP_CONFIG_DIR/$relativePath";
     1.7 +		# TODO: stop if directory already exists / only add public link?
     1.8  		mkdir -p "$absolutePath";
     1.9  		echo "$2" > "$absolutePath/url.txt"
    1.10  		echo "submited" > "$absolutePath/state.txt"
    1.11 @@ -206,7 +207,7 @@
    1.12  # Environment: server
    1.13  # User: $VCS_BACKUP_MANAGER
    1.14  vcs_backup_public_serverListRepositories() {
    1.15 -	printRecfileKeyValue "%rec"  "repositories";
    1.16 +	printRecfileKeyValue "%rec"  "repository";
    1.17  	printRecfileKeyValue "%type" "bytes int";
    1.18  	printRecfileKeyValue "%type" "public bool";
    1.19  	echo;
    1.20 @@ -248,7 +249,6 @@
    1.21  		vcsType=$(echo "$d" | sed 's@/.*@@g');
    1.22  		absolutePath="$VCS_BACKUP_CURRENT_DIR/$d";
    1.23  
    1.24 -
    1.25  		pullStarted=$(date --iso-8601=s);
    1.26  		pullStartedMiliseconds=$(($(date +%s%N)/1000000));
    1.27  		pullFinished="";
    1.28 @@ -280,7 +280,45 @@
    1.29  # User: root
    1.30  # should be called from cron (usually every day) after Pull (see above)
    1.31  vcs_backup_public_serverSnapshotCronTask() {
    1.32 -	return;
    1.33 +	printRecfileKeyValue "%rec"  "snapshot";
    1.34 +	printRecfileKeyValue "%type" "started date";
    1.35 +	printRecfileKeyValue "%type" "finished date";
    1.36 +	printRecfileKeyValue "%type" "duration int";
    1.37 +	printRecfileKeyValue "%type" "resultCode int";
    1.38 +	
    1.39 +	find "$VCS_BACKUP_CONFIG_DIR" -name url.txt -printf '%P\n' | sort | xargs dirname | while read d; do
    1.40 +		state=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/state.txt");
    1.41 +		vcsType=$(echo "$d" | sed 's@/.*@@g');
    1.42 +		absolutePath="$VCS_BACKUP_CURRENT_DIR/$d";
    1.43 +
    1.44 +		started=$(date --iso-8601=s);
    1.45 +		startedMiliseconds=$(($(date +%s%N)/1000000));
    1.46 +		finished="";
    1.47 +		duration="";
    1.48 +		result="";
    1.49 +		resultCode="";
    1.50 +		snapshotPath="";
    1.51 +		if [[ "$state" == "cloned" ]]; then
    1.52 +			snapshotPath="$VCS_BACKUP_SNAPSHOT_DIR/$d/$(date --iso-8601=date)";
    1.53 +			mkdir -p $(dirname "$snapshotPath");
    1.54 +			result=$(btrfs subvolume snapshot -r "$absolutePath" "$snapshotPath" 2>&1);
    1.55 +			resultCode=$?;
    1.56 +			finished=$(date --iso-8601=s);
    1.57 +			finishedMiliseconds=$(($(date +%s%N)/1000000));
    1.58 +			duration=$(( $finishedMiliseconds - $startedMiliseconds ));
    1.59 +		fi
    1.60 +
    1.61 +		printRecfileKeyValue "currentPath"     "$absolutePath";
    1.62 +		printRecfileKeyValue "snapshotPath"    "$snapshotPath";
    1.63 +		printRecfileKeyValue "type"            "$vcsType";
    1.64 +		printRecfileKeyValue "state"           "$state";
    1.65 +		printRecfileKeyValue "started"         "$started";
    1.66 +		printRecfileKeyValue "finished"        "$finished";
    1.67 +		printRecfileKeyValue "duration"        "$duration";
    1.68 +		printRecfileKeyValue "resultCode"      "$resultCode";
    1.69 +		printRecfileKeyValue "message"         "$result";
    1.70 +		echo;
    1.71 +	done
    1.72  }
    1.73  
    1.74  # --- Single entry-point: --------------------------------------------------------------------------