Upload files to "/"
This commit is contained in:
commit
a7b7ab9957
10
grs.service
Normal file
10
grs.service
Normal file
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Git Repository Synchronizer
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/mnt/git-repository-archive
|
||||
ExecStart=/mnt/git-repository-archive/grs.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
54
grs.sh
Normal file
54
grs.sh
Normal file
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 1/10 = 0.1 = 10%
|
||||
thresholdFactor=10
|
||||
sleepTime=10m
|
||||
|
||||
#while true; do
|
||||
|
||||
if [ ! -d repositories ]; then mkdir repositories; fi
|
||||
if [ ! -d snapshots ]; then mkdir snapshots; fi
|
||||
|
||||
cd repositories
|
||||
for repository in *; do
|
||||
if [ ! -d "$repository" ]; then continue; fi
|
||||
if [ ! -d "../snapshots/$repository" ]; then cp -rf "$repository" ../snapshots; fi
|
||||
|
||||
log=$(echo [$(date +"%Y-%m-%d %H:%M:%S")] Checking \"$repository\")
|
||||
echo "$log"
|
||||
|
||||
cd "$repository"
|
||||
gitOutput=$(git pull --recurse-submodules=on-demand)
|
||||
echo "$gitOutput"
|
||||
cd ..
|
||||
if [ "$gitOutput" == "Already up to date." ]; then continue; fi
|
||||
|
||||
echo "$log" >> ../log.txt
|
||||
echo "$gitOutput" >> ../log.txt
|
||||
|
||||
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
|
||||
log=$(echo [$(date +"%Y-%m-%d %H:%M:%S")] Updating \"$repository\")
|
||||
echo "$log"
|
||||
echo "$log" >> ../log.txt
|
||||
echo >> ../log.txt
|
||||
|
||||
rm -rf "../snapshots/$repository"
|
||||
cp -rf "$repository" ../snapshots
|
||||
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
|
||||
|
||||
tar -czf "../snapshots/$snapshotTime $repository.tar.gz" "../snapshots/$repository"
|
||||
rm -rf "../snapshots/$repository"
|
||||
cp -rf "$repository" ../snapshots
|
||||
done
|
||||
cd ..
|
||||
|
||||
# sleep $sleepTime
|
||||
#done
|
Loading…
Reference in New Issue
Block a user