Episode 19: Nextcloud AIO, OpenCloud and Seafile measured with the same test data on the same server
This commit is contained in:
parent
76a3132a17
commit
145d318452
70 changed files with 3296 additions and 0 deletions
86
filesync/client/m.sh
Normal file
86
filesync/client/m.sh
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env bash
|
||||
# m.sh: Messschritte auf ep19fs-cli. Client A = Linux-Nutzer clienta, Client B = clientb.
|
||||
# Zugang aus /root/ep19fs/env (0640, Gruppe ep19). Keine Geheimnisse im Output.
|
||||
set -u
|
||||
source /root/ep19fs/lib.sh
|
||||
set -a; source /root/ep19fs/env; set +a
|
||||
SRV=203.0.113.10; H=$(echo "${NC_URL:-https://x}" | sed 's#https://##')
|
||||
A() { sudo -u clienta -H "$@"; }
|
||||
B() { sudo -u clientb -H "$@"; }
|
||||
acct() { for u in clienta clientb; do iptables -C OUTPUT -d $SRV -m owner --uid-owner $u -j ACCEPT 2>/dev/null || iptables -I OUTPUT -d $SRV -m owner --uid-owner $u -j ACCEPT; done; }
|
||||
tx() { iptables -L OUTPUT -v -x -n | awk -v id="$(id -u $1)" '$0 ~ ("owner UID match " id "$") {print $2; exit}'; }
|
||||
api() { python3 /root/ep19fs/api.py "$@"; }
|
||||
gb() { python3 -c "print(f'{$1/1e6:.1f} MB')"; }
|
||||
acct
|
||||
# ---------- Werkzeug-Aufrufe je Produkt ----------
|
||||
nc_sync() { # nc_sync USER LOCALDIR REMOTEPATH
|
||||
sudo -u $1 -H nextcloudcmd -n --non-interactive --path "$3" "$2" "$NC_URL" > /tmp/ncc-$1.log 2>&1; echo "nextcloudcmd exit $? ($(grep -ciE 'error|fail' /tmp/ncc-$1.log) Zeilen mit error/fail im Log)"; }
|
||||
rc_copy() { # rc_copy USER LOCALDIR REMOTE:PATH
|
||||
sudo -u $1 -H rclone copy "$2" "$3" --stats-one-line --stats 0 > /tmp/rc-$1.log 2>&1; echo "rclone exit $?"; tail -2 /tmp/rc-$1.log | sed 's/^/ /'; }
|
||||
oc_sync() { # oc_sync USER LOCALDIR REMOTEFOLDER
|
||||
sudo -u $1 -H OPENCLOUD_TOKEN="$OC_TOKEN" opencloudcmd --non-interactive -u "$OC_USER" --remote-folder "/$3" "$OC_URL" "$OC_SPACE" "$2" > /tmp/occ-$1.log 2>&1; echo "opencloudcmd exit $? ($(grep -ciE 'error|fail' /tmp/occ-$1.log) Zeilen mit error/fail im Log)"; }
|
||||
osync() { # osync USER DIR REMOTE : offizieller Client je Produkt
|
||||
case $P in nc) nc_sync $1 $2 /$3;; oc) oc_sync $1 $2 $3;; esac; }
|
||||
ls_state() { echo " A: $(cd $1 && find . -type f | sort | head -20 | tr '\n' ' ')"; echo " B: $(cd $2 && find . -type f | sort | head -20 | tr '\n' ' ')"; }
|
||||
case $1 in
|
||||
setup-creds) # .netrc und rclone.conf je Nutzer (einmalig), ohne Ausgabe der Werte
|
||||
for u in clienta clientb; do h=$(eval echo ~$u)
|
||||
[ -n "${NC_PASS:-}" ] && { printf 'machine %s login %s password %s\n' "$H" "$NC_USER" "$NC_PASS" > $h/.netrc; chmod 600 $h/.netrc; chown $u $h/.netrc; }
|
||||
mkdir -p $h/.config/rclone; : > $h/.config/rclone/rclone.conf
|
||||
[ -n "${NC_PASS:-}" ] && printf '[nc]\ntype = webdav\nurl = %s/remote.php/dav/files/%s\nvendor = nextcloud\nuser = %s\npass = %s\n\n' "$NC_URL" "$NC_USER" "$NC_USER" "$(rclone obscure "$NC_PASS")" >> $h/.config/rclone/rclone.conf
|
||||
[ -n "${OC_TOKEN:-}" ] && printf '[oc]\ntype = webdav\nurl = %s/remote.php/dav/spaces/%s\nvendor = infinitescale\nuser = %s\npass = %s\n\n' "$OC_URL" "$OC_SPACE" "$OC_USER" "$(rclone obscure "$OC_TOKEN")" >> $h/.config/rclone/rclone.conf
|
||||
[ -n "${SF_PASS:-}" ] && printf '[sf]\ntype = webdav\nurl = %s/seafdav\nvendor = other\nuser = %s\npass = %s\n\n' "$SF_URL" "$SF_USER" "$(rclone obscure "$SF_PASS")" >> $h/.config/rclone/rclone.conf
|
||||
chown -R $u $h/.config; chmod 600 $h/.config/rclone/rclone.conf; done; echo "creds ok";;
|
||||
prep) # prep P MODE: lokale Kopie, Ziel auf dem Server leeren (nicht gemessen)
|
||||
P=$2; MODE=$3; d=/home/clienta/up/$P-$MODE; rm -rf $d; mkdir -p $d; cp -r /data/testset/small /data/testset/big $d/; chown -R clienta $d
|
||||
case $P in nc|oc) api $P rmtree up-$MODE; api $P mkcol up-$MODE;; esac
|
||||
echo "prep $P $MODE: $(find $d -type f | wc -l) Dateien lokal";;
|
||||
up) # up P MODE: Hochladen messen
|
||||
P=$2; MODE=$3; d=/home/clienta/up/$P-$MODE; b0=$(tx clienta); t0=$(now); echo "start $(ts) UTC"
|
||||
case $P-$MODE in
|
||||
nc-official) nc_sync clienta $d /up-official;;
|
||||
nc-rclone) rc_copy clienta $d nc:up-rclone;;
|
||||
oc-official) oc_sync clienta $d up-official;;
|
||||
oc-rclone) rc_copy clienta $d oc:up-rclone;;
|
||||
esac
|
||||
t1=$(now); b1=$(tx clienta); echo "ende $(ts) UTC, Dauer $(el $t0 $t1) s, gesendet $(gb $((b1-b0)))"
|
||||
echo "Server: $(api $P count up-$MODE) (Dateien Bytes)";;
|
||||
delta) # delta P: 2-GiB-Datei synchron, dann 1 MiB in der Mitte ändern, erneut synchronisieren, Bytes messen
|
||||
P=$2; d=/home/clienta/d/$P; rm -rf $d; mkdir -p $d; cp /data/testset/big/big.bin $d/; chown -R clienta /home/clienta/d
|
||||
api $P rmtree delta; api $P mkcol delta
|
||||
echo "Erstabgleich (nicht bewertet):"; b0=$(tx clienta); t0=$(now); osync clienta $d delta; echo " $(el $t0 $(now)) s, gesendet $(gb $(( $(tx clienta)-b0 )))"
|
||||
echo "Änderung: dd 1 MiB Zufall an Offset 1024 MiB (conv=notrunc), Dateigröße bleibt 2 GiB"
|
||||
sudo -u clienta dd if=/dev/urandom of=$d/big.bin bs=1M count=1 seek=1024 conv=notrunc status=none; sha256sum $d/big.bin | cut -c1-16
|
||||
b0=$(tx clienta); t0=$(now); osync clienta $d delta; t1=$(now); echo "Sync nach Änderung: $(el $t0 $t1) s, gesendet $(gb $(( $(tx clienta)-b0 )))"
|
||||
echo "rclone zum Vergleich (gleiche Änderung, rclone copy auf denselben Ordner):"
|
||||
sudo -u clienta dd if=/dev/urandom of=$d/big.bin bs=1M count=1 seek=512 conv=notrunc status=none
|
||||
b0=$(tx clienta); t0=$(now); rc_copy clienta $d $P:delta; echo " rclone: $(el $t0 $(now)) s, gesendet $(gb $(( $(tx clienta)-b0 )))";;
|
||||
conflict) # conflict P: dieselbe Datei auf A und B offline geändert
|
||||
P=$2; da=/home/clienta/c/$P; db=/home/clientb/c/$P; rm -rf $da $db; sudo -u clienta mkdir -p $da; sudo -u clientb mkdir -p $db
|
||||
api $P rmtree conflict; api $P mkcol conflict
|
||||
echo "Angebot Version 1" | sudo -u clienta tee $da/angebot.txt >/dev/null; osync clienta $da conflict; osync clientb $db conflict
|
||||
echo "Ausgangslage nach Erstabgleich:"; ls_state $da $db
|
||||
echo "Offline: A schreibt 'Version A', B schreibt 'Version B' (kein Sync dazwischen)"
|
||||
echo "Angebot Version A (Preis 900)" | sudo -u clienta tee $da/angebot.txt >/dev/null; sleep 2
|
||||
echo "Angebot Version B (Preis 1200)" | sudo -u clientb tee $db/angebot.txt >/dev/null
|
||||
echo "A synchronisiert zuerst:"; osync clienta $da conflict
|
||||
echo "B synchronisiert danach:"; osync clientb $db conflict
|
||||
echo "A synchronisiert noch einmal:"; osync clienta $da conflict
|
||||
echo "Ergebnis:"; ls_state $da $db
|
||||
for f in $da/* ; do echo " A $(basename "$f"): $(cat "$f")"; done; for f in $db/* ; do echo " B $(basename "$f"): $(cat "$f")"; done
|
||||
echo " Server: $(api $P ls conflict)";;
|
||||
delete) # delete P: Ordner mit 5000 Dateien auf A gelöscht, propagiert das, wie kommt er zurück
|
||||
P=$2; da=/home/clienta/x/$P; db=/home/clientb/x/$P
|
||||
if [ "${3:-}" != again ]; then rm -rf $da $db; sudo -u clienta mkdir -p $da; sudo -u clientb mkdir -p $db
|
||||
api $P rmtree del; api $P mkcol del; cp -r /data/testset/small $da/projekt; chown -R clienta $da; fi
|
||||
echo "Abgleich A und B:"; t0=$(now); osync clienta $da del; osync clientb $db del; echo " $(el $t0 $(now)) s"
|
||||
echo " A: $(find $da -type f | wc -l) Dateien, B: $(find $db -type f | wc -l) Dateien, Server: $(api $P count del)"
|
||||
echo "$(ts) A löscht den Ordner projekt (rm -rf) und synchronisiert"; rm -rf $da/projekt; t0=$(now); osync clienta $da del; echo " A-Sync $(el $t0 $(now)) s"
|
||||
echo " Server nach A-Sync: $(api $P count del)"
|
||||
t0=$(now); osync clientb $db del; echo "$(ts) B synchronisiert ($(el $t0 $(now)) s): B hat noch $(find $db -type f | wc -l) Dateien"
|
||||
echo "$(ts) Wiederherstellen aus dem Papierkorb des Servers (WebDAV MOVE, wie der Knopf in der Weboberfläche):"
|
||||
t0=$(now); api $P restore projekt del/projekt; echo " Server: $(api $P count del)"
|
||||
osync clientb $db del; osync clienta $da del; t1=$(now)
|
||||
echo "$(ts) nach je einem Sync: A $(find $da -type f | wc -l), B $(find $db -type f | wc -l) Dateien; vom Restore-Start bis beide Clients vollständig $(el $t0 $t1) s";;
|
||||
*) echo "unbekannt: $1";;
|
||||
esac
|
||||
Loading…
Add table
Add a link
Reference in a new issue