Batch-/Shellscript rsync

web2null

ehem. assactions
ID: 131418
L
20 April 2006
1.775
165
Hoffe hier kennt sich einer ein wenig mit rsync aus, brauche da unbedingt bissel hilfe.

Also es geht um folgendes

Ordnerstruktur


Soll gebackupt werden in

Upload/Kunde/*/web

Das Problem bei dem ganzen ist, das der inhalt von Kunde dynamisch ist und bei 400 + Kunden alles vorzudefinieren wäre ne menge arbeit. Wie löse ich das am besten?

Ansatz war:

@ECHO OFF

rsync.exe -a -v --delete --recursive /cygdrive/C/xampp/htdocs/script/kunden/*/Web/ /cygdrive/C/xampp/htdocs/script/upload/kunden/*/Web/
pause

was natürlich nicht geht weil er nicht weiss wie * heißt. Weiß einer wie das mit rsync geht?
 
Ohne es getestet zu haben würde ich auf etwas in dieser Art tippen:
Code:
@ECHO OFF

cd /cygdrive/C/xampp/htdocs/script/kunden/
rsync.exe -a -v --delete --recursive */Web/ /cygdrive/C/xampp/htdocs/script/upload/kunden/
pause
 
Wenn auch mit der Gefahr, das Problem nicht ganz erfasst zu haben, da ich rsync nicht kenne...
Du willst diesen Backup-Prozess für jedes Verzeichnis machen, weißt aber natürlich nicht, welche Verzeichnisse da jetzt konkret drin sind. Richtig?

Wie siehts denn dann mit ner for-Schleife aus?
 
machen wir mal ein Beispiel damit es verständlich ist:

Vorhanden ist:

Code:
Kunde/abc/Web/
  + Logo.pdf
  + XML.pdf
Code:
in abc ist:
 + xcd.pdf
 Ordner(Web)
Code:
Kunde/kjb/Web/
  + xc11.pdf
  + kd.pdf
Code:
in kjb ist:
+ ik.pdf
Ordner(Web)
Ordner(xcq)
daraus soll eine kopie werden unzwar

Code:
upload/Kunde/abc/Web/
  + Logo.pdf
  + XML.pdf
Code:
upload/Kunde/kjb/Web/
   + xc11.pdf
   + kd.pdf
Dabei ist darauf zu achten das in dem Ordner Kunde ab und zu neue hinzukommen und natürlich auch neue Daten in Web rein kommen.

Soll halt die ordnerstruktur upload/Kunde/*/web/ erstellen und die daten aus web sollen halt dort wieder rein
 
Hallo


rsync -avb /kunde /upload

vor Kunde und /upload dann deine Pfadeangen

-b kopiert rekursiv

siehe auch man rsync

du kannst ja vorher mal

rsync -avbd /kunde /upload
laufen lassen -d = dry-run
 
Hallo


rsync -avb /kunde /upload

vor Kunde und /upload dann deine Pfadeangen

-b kopiert rekursiv

siehe auch man rsync

du kannst ja vorher mal

rsync -avbd /kunde /upload
laufen lassen -d = dry-run

ja nur so nimmt der doch auch alle anderen daten die z.b. direkt im kundenordner sind, ich benötige bloss die ordnerstruktur und die daten aus dem ordner Web
 
Rsync filter hab' ich bisher immer nur mit --exclude verwendet aber man kann das ganze sehr extrem betreiben, es giebt eine ganze Sektion mit Filter Rules:
https://www.samba.org/ftp/rsync/rsync.html
The filter rules allow for flexible selection of which files to transfer (include) and which files to skip (exclude). The rules either directly specify include/exclude patterns or they specify a way to acquire more include/exclude patterns (e.g. to read them from a file).

As the list of files/directories to transfer is built, rsync checks each name to be transferred against the list of include/exclude patterns in turn, and the first matching pattern is acted on: if it is an exclude pattern, then that file is skipped; if it is an include pattern then that filename is not skipped; if no matching pattern is found, then the filename is not skipped.

Rsync builds an ordered list of filter rules as specified on the command-line. Filter rules have the following syntax:

RULE [PATTERN_OR_FILENAME]
RULE,MODIFIERS [PATTERN_OR_FILENAME]

You have your choice of using either short or long RULE names, as described below. If you use a short-named rule, the ',' separating the RULE from the MODIFIERS is optional. The PATTERN or FILENAME that follows (when present) must come after either a single space or an underscore (_). Here are the available rule prefixes:

exclude, - specifies an exclude pattern.
include, + specifies an include pattern.
merge, . specifies a merge-file to read for more rules.
dir-merge, : specifies a per-directory merge-file.
hide, H specifies a pattern for hiding files from the transfer.
show, S files that match the pattern are not hidden.
protect, P specifies a pattern for protecting files from deletion.
risk, R files that match the pattern are not protected.
clear, ! clears the current include/exclude list (takes no arg)

When rules are being read from a file, empty lines are ignored, as are comment lines that start with a "#".

Note that the --include/--exclude command-line options do not allow the full range of rule parsing as described above -- they only allow the specification of include/exclude patterns plus a "!" token to clear the list (and the normal comment parsing when rules are read from a file). If a pattern does not begin with "- " (dash, space) or "+ " (plus, space), then the rule will be interpreted as if "+ " (for an include option) or "- " (for an exclude option) were prefixed to the string. A --filter option, on the other hand, must always contain either a short or long rule name at the start of the rule.

Note also that the --filter, --include, and --exclude options take one rule/pattern each. To add multiple ones, you can repeat the options on the command-line, use the merge-file syntax of the --filter option, or the --include-from/--exclude-from options.

Ich kann dir ned genau sagen wie das ganze dann aussieht aber ich werd' mir nochmal genau nachlesen :)

Notfalls wuerde ich mit Bash eben schnell was machen:
Code:
#!/bin/bash
cd Kunde/
for i in *; do
  rsync -a -v --delete --recursive $i/Web /ziel/pfad/$i
done

Bash for live

Damit loopd man ueber alle Kunden und laesst jedesmal ein rsync laufen :D

Keine Garantie dass es unter Cygwin funzt :evil:
 
leider komm ich nicht weiter :/ scheiss windoof. Theoretisch wäre es doch auch mit PHP möglich oder?

Hab es nun so gelöst, ist zwar nicht die beste, aber besser als garnix und später einfach nochmal kurz mit PHP filtern wen alles online ist.

Code:
rsync -avb --exclude=*.psd --exclude=*.eps --exclude=*.doc --exclude=*.png --exclude=*.gif --exclude=/kunden/*.* --exclude=*.tif --exclude=*.db --exclude=kunden_*/ --exclude=*.indd  --exclude=*.tiff --exclude=*.jpg  --include=web/*.pdf  /cygdrive/R/xxx/anzeigenkunden/ /cygdrive/C/xxx/upload
 
Zuletzt bearbeitet:
leider komm ich nicht weiter :/ scheiss windoof.
Windows kennt auch ne for-Schleife... sonst hätt ich es ja nicht vorgeschlagen ;)
Theoretisch wäre es doch auch mit PHP möglich oder?
Praktisch auch. Mit opendir(), readdir(), closedir() kannst du die Verzeichnisstruktur auslesen, isdir(), isfile() überprüfen, welche Art von Datei vorliegt. Mit system() kannst du dann einen Befehl auf der Shell ausführen.