Update grs.sh
This commit is contained in:
parent
13ea574781
commit
949ff63c33
35
grs.sh
35
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 ..
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user