From 949ff63c330b8ef124018748285a5b972400eb5a Mon Sep 17 00:00:00 2001 From: Mohammed Goder Date: Sat, 23 Mar 2024 15:33:40 -0500 Subject: [PATCH] Update grs.sh --- grs.sh | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/grs.sh b/grs.sh index 42477f7..4c73875 100644 --- a/grs.sh +++ b/grs.sh @@ -1,5 +1,7 @@ #!/bin/bash +logPath=log.txt + # 1/10 = 0.1 = 10% thresholdFactor=10 sleepTime=10m @@ -21,32 +23,37 @@ for repository in *; do gitOutput=$(git pull --recurse-submodules=on-demand) echo "$gitOutput" cd .. - if [ "$gitOutput" == "Already up to date." ]; then continue; fi + if [ "$gitOutput" == "Already up to date." ] || [ "$gitOutput" == "" ]; then continue; fi - echo "$log" >> ../log.txt - echo "$gitOutput" >> ../log.txt + cd .. + echo "$log" >> "$logPath" + echo "$gitOutput" >> "$logPath" - snapshotSize=$(($(du -sb "../snapshots/$repository" | cut -f1) - $(du -sb "../snapshots/$repository/.git" | cut -f1))) - if [ $(($snapshotSize - ($snapshotSize / $thresholdFactor))) -lt $(($(du -sb "$repository" | cut -f1) - $(du -sb "$repository/.git" | cut -f1))) ]; then + snapshotSize=$(($(du -sb "snapshots/$repository" | cut -f1) - $(du -sb "snapshots/$repository/.git" | cut -f1))) + if [ $(($snapshotSize - ($snapshotSize / $thresholdFactor))) -lt $(($(du -sb "repositories/$repository" | cut -f1) - $(du -sb "repositories/$repository/.git" | cut -f1))) ]; then log=$(echo [$(date +"%Y-%m-%d %H:%M:%S")] Updating \"$repository\") echo "$log" - echo "$log" >> ../log.txt - echo >> ../log.txt + echo "$log" >> "$logPath" + echo >> "$logPath" - rm -rf "../snapshots/$repository" - cp -rf "$repository" ../snapshots + rm -rf "snapshots/$repository" + cp -rf "repositories/$repository" snapshots + + cd repositories continue fi snapshotTime=$(echo [$(date +"%Y-%m-%d %H'%M'%S")]) log=$(echo $snapshotTime Snapshotting \"$repository\") echo "$log" - echo "$log" >> ../log.txt - echo >> ../log.txt + echo "$log" >> "$logPath" + echo >> "$logPath" - tar -czf "../snapshots/$snapshotTime $repository.tar.gz" "../snapshots/$repository" - rm -rf "../snapshots/$repository" - cp -rf "$repository" ../snapshots + tar -czf "snapshots/$snapshotTime $repository.tar.gz" "snapshots/$repository" + rm -rf "snapshots/$repository" + cp -rf "repositories/$repository" snapshots + + cd repositories done cd ..