Reputation: 75
My goal is to make an Electron application, which synchronizes clients' folder with server. To explain it more clearly:
Simply, the application has to make sure, that client has EXACT copy of host server's folder.
So far, I did this via wget -m, however frequently wget did not recognize, that some files changed and left clients with outdated files.
Recently I've heard of zsync-windows and webtorrent npm package, but I am not sure which approach is right and how to actually accomplish my goal. Thanks for any help.
Upvotes: 5
Views: 1963
Reputation: 1032
rsync is a good approach but you will need to access it via node.js
An npm package like this may help you: https://github.com/mattijs/node-rsync
But things will get slightly more difficult on windows systems: How to get rsync command on windows?
Upvotes: 2
Reputation: 1594
Given it's a folder list (and therefore having simple filenames without spaces, etc.), you can pick the filenames with below code
# Get last item from each line of FILELIST
awk '{print $NF}' FILELIST | sort >weblist
# Generate a list of your files
find -type f -print | sort >mylist
# Compare results
comm -23 mylist weblist >diffs
# Remove old files
xargs -r echo rm -fv <diffs
you'll need to remove the final echo
to allow rm
work
Next time you want to update your mirror, you can modify the comm
line (by swapping the two file arguments) to find the set of files you don't have, and feed those to wget
.
or
rsync -av --delete https://mirror.abcd.org/xyz/xyz-folder/ my-client-xyz-directory/
Upvotes: 0
Reputation: 909
You can use rsync
which is widely used for backups and mirroring and as an improved copy command for everyday use. It offers a large number of options that control every aspect of its behaviour and permit very flexible specification of the set of files to be copied.
It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination.
For your use case:
If the client has the files, but some files have been updated on the server, the application deletes ONLY the outdated files (leaving the unmodified ones) and downloads the updated files. Use: –remove-source-files or -delete based on whether you want to delete the outdated files from the source or the destination.
If a file has been removed from the host server but is present at the client's folder, the application deletes the file. Use: -delete option of rsync.
rsync -a --delete source destination
Upvotes: 0
Reputation: 539
If you have ssh access to the server an approach could be using rsync through a Node.js package.
There's a good article here on how to implement this.
Upvotes: 0