Re: How to sync a UNC path to a USB memory stick in Windows?
by roboticus (Chancellor) on May 31, 2006 at 02:28 UTC
|
OfficeLinebacker:
The only thing I can think of is: Since you're using File::Find to traverse the directory tree to delete, why not just change the logic to use File::Find on the source drive, and then build the directory structure in the same way you're tearing it down. Then you can omit the xcopy...
Regarding cut & paste to/from the DOS window: What works for me (Windows 2000 Professional) is to right-click the title bar of the DOS app, and select Edit->Mark, then use the mouse to highlight text and press the Enter key. That puts it on my clipboard so I can paste with ^V in *real* applications... 8^). I dunno if it'll work for you, but maybe it will.
--roboticus | [reply] |
|
|
Hey, buddy, thanks for replying!
OK, I'll have to play with File::Find and see if it will take UNC arguments. Also, if File::Find will, then would it be logical to assume File::Copy would, too? And doesn't File::Copy have a recursive add-on?
I happen to be home right now and I got to poking around on my laptop, and whatddya know, someone has written a perl script that maps drives when you're away from the office. Seems fairly simple in that it uses 'net use.' So I may look into that as well.
Thanks again,
J
UPDATE: Also File::Repl looks interesting and appears to work with UNCs.
_________________________________________________________________________________
I like computer programming because it's like Legos for the mind.
| [reply] |
|
|
I think File::Copy handles UNC paths. (In the cygwin perl (the one I use) I believe that filename resolution is ultimately passed on to the OS, so it has access to all the files the OS does.)
I don't know about the recursive add-on, but I figure while you're doing your File::Find, your original routine has access to the full path of the filename. Given that, you could copy it over to the destination device.
--roboticus
| [reply] |
|
|
"right-click the title bar of the DOS app, and select Edit->Mark, then use the mouse to highlight text and press the Enter key.
Save some steps:
Once the DOS window has focus, there's no need to select edit.
Just use the mouse to highlight the text to copy to the clipboard and hit enter when the highlighting is complete. NB: you can take a set of columns, but to capture continuous text, you'll need to be careful to highlight the full (virutal) width of the DOS screen... and when chars/line > 256, you'll have to replace the lineendings in the copy you "paste with ^V in *real* applications...."
That begs another question -- nay, "a mystery" to me: why did M$ bother with the "mark" option at all?
Update Re Roboticus' below: I'm stuck (this week) with w2k... and somewhat surprised by the question, since above ( in [id://#552678] ) you remarked "What works for me (Windows 2000 Professional) ...."
| [reply] |
|
|
| [reply] |
|
|
|
|
Re: How to sync a UNC path to a USB memory stick in Windows?
by planetscape (Chancellor) on May 31, 2006 at 09:58 UTC
|
roboticus' instructions in how to copy & paste from a DOS command prompt should work flawlessly for you.*
While I have never used Rsync, I have seen many recommendations here on PM. These links may be helpful:
Rsync
Rsync mirroring howto and FAQ
Easy Automated Snapshot-Style Backups with Rsync
Personally, I heartily recommend WinZip and its command-line interface (download separately; registered version only IIRC). It's easy for non-tech heads and very portable.
HTH,
* Update: There is also a very nice little utility called, predictably, "Clipboard" which allows you to capture output from a DOS command prompt and copy it to the Windows Clipboard. The article may be found here: Print From Any Console Application, by Bill Wagner (a free, AFAIK, registration is required). If you go to Visual Studio Magazine and type vsep030228cs into the "Locator+ Code" field, you should be able to download the C# source as a .zip file. Usage is as follows:
Prompt> dir | clipboard -c
..copies to the clipboard.
Prompt> dir | clipboard -p
.. Prints the output
Prompt> dir | clipboard -c -p
Copies to the clipboard, and prints it.
| [reply] [d/l] |
Re: How to sync a UNC path to a USB memory stick in Windows?
by aufflick (Deacon) on May 31, 2006 at 06:21 UTC
|
This Novell article:
http://www.novell.com/coolsolutions/appnote/14729.html
Seems to discuss how to install and use a minimal package that installs the cygwin rsync utility. The UNC path is effectively a local drive, and a cygwin utility should work directly with it without you needing to map it to a drive letter (although you could do that in a Perl/Batch script anyway). Since you only want local syncing there's no need to run the rsync daemon, just use it as a commandline tool.
Syncing file structures efficiently can be a tricky problem, so rsync will save you a lot of work. A big benefit of using rsync in this case (rather than replacing the files every night) is that you will be making many less write cycles to the memory stick, so it will last a lot longer. | [reply] |
Re: How to sync a UNC path to a USB memory stick in Windows?
by BrowserUk (Patriarch) on May 31, 2006 at 07:21 UTC
|
This functionality is already available in modern versions of Windows. Click the 'My breifcase' icon on your desktop and follow the instructions.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
|
|
I'm not sure that Windows always comes with a Briefcase. I've got XP Home, and I don't recall ever seeing the Briefcase on it. In fact, I don't remember seeing it since Win98... I'm thinking that it might be something that some OEM's choose to leave off.
Update:[id://BrowserUK] is correct; I *do* have Briefcase, if I use the Desktop context menu to access it. I think I got confused because older versions of Windows had a Briefcase icon on the Desktop by default. I stand corrected.
| [reply] |
|
|
| [reply] |
Re: How to sync a UNC path to a USB memory stick in Windows?
by roboticus (Chancellor) on May 31, 2006 at 11:13 UTC
|
OfficeLinebacker:
...and then I woke up, had a cuppa coffee, and said to myself: "Hmmm, someone must've already done this. Let's check CPAN!". (When am I going to learn to check CPAN first? I too often find myself writing code, and when I'm 75% of the way done, I then go "D'oh!" and check CPAN, and find what I need. Ah, well, the coding is at least teaching me Perl...)
And I found three modules that would do what you want: File::DirSync, File::Backup and File::Repl. I stopped looking after these three, even though search.cpan.org wanted to give me many more pages...
Another item I stumbled across while looking is File::Set, which might be a useful base if you want to build something a bit more custom.
--roboticus | [reply] |
Re: How to sync a UNC path to a USB memory stick in Windows?
by pKai (Priest) on May 31, 2006 at 07:56 UTC
|
A few things in random order:
- If you can map the UNC resource and copy to it as a drive letter, you should also be able to copy to the UNC path directly. There is no special magic in the drive letter mapping and xcopy can handle that without problems.
- As you say you are not very familiar with UNC: Have you checked the correctness of your path? Your sample code reads $source="\\\\server\\dir\\files\\";. So "dir" is a "share" provided by server?
- Using robocopy.exe instead of xcopy is more flexible. At least I always prefered that for the last ten years for such synchronisation task under Windows. Additional pro is better error messages in case of failure. Cons would be that you have to grab a copy of robocopy from a "Windows Resource Kit" and copy it to the machine for using.
- When you go the road with using Perl built in copy mechanism/modules, be aware that all path separators can be written as forward slashes, (i.e. $source = "//server/share/dir";) because the underlying API did allow that since earliest DOS times; only the DOS command prompt forces you to use backslashes.
| [reply] [d/l] [select] |
Re: How to sync a UNC path to a USB memory stick in Windows?
by OfficeLinebacker (Chaplain) on May 31, 2006 at 13:49 UTC
|
Greetings, esteemed monks!
I am so thankful to each of you--this is what PM is all about. I was talking to a coworker today on the way to work and I realized (like many of you also did) that this can be done outside of Perl with a simple .BAT script. The briefcase idea sounds fantastic. I think I am going to pursue that one first, and go from there.
I have a meeting to go to at 10:00 EDT, but I will keep you updated. Thanks so much for the thoughtful replies, and I'll get my votes out to you!
_________________________________________________________________________________
I like computer programming because it's like Legos for the mind.
| [reply] |
Re: How to sync a UNC path to a USB memory stick in Windows?
by salva (Canon) on May 31, 2006 at 08:41 UTC
|
| [reply] |
Re: How to sync a UNC path to a USB memory stick in Windows?
by nimdokk (Vicar) on May 31, 2006 at 12:02 UTC
|
One note, you might want to consider using File::Spec. It will help in using UNC paths without having to escape directory seperators (and to some extent) helps in creating making paths without having to worry about OS specific directory seperators (Mac OSX, *nix, Windows, etc.). Just a thought if you need to use UNC paths only (no mapped drives). | [reply] |
Re: How to sync a UNC path to a USB memory stick in Windows?
by OfficeLinebacker (Chaplain) on May 31, 2006 at 15:42 UTC
|
Hey folks, just to follow up: as BrowserUK noted, to make a new briefcase, I simply right clicked on the desktop and selected New->Briefcase, and there it was. I moved the briefcase to the memory stick (D:), and then copied a directory from one of my network drives into the briefcase. It proceeded like a normal copy.
Then, I added files and a directory (in Linux--it's a Samba share) and right clicked on the briefcase and selected "Update All." A window of what had changed popped up and I clicked the "Update All" button. Then I tried deleting some of the stuff I just created and the same thing happened. When new files need to be copied, there's a green arrow, and when there are orphans in the briefcase, there are red arrows. All seems to work exactly as promised. One interesting thing to note is that if I only do a mkdir on the source and then update the briefcase, it's "smart" enough to know it's just an empty directory and states there are no updates.
Anyway, it turns out that the problem is indeed trivial in Windows and it just took the right information. Thanks again, and feel free to add comments. I hope that this solution is acceptable; it's not EXACTLY what I had in mind, as it's not just an icon that the people can double-click once, and it has to be set up separately for each person (as opposed to a script I could just email to people with some instructions), but I think it's the best solution.
_________________________________________________________________________________
I like computer programming because it's like Legos for the mind.
| [reply] |
|
|
| [reply] [d/l] |
|
|
Browser, I'm already much obliged for your help, and I'd be even more obliged if you were to happen on something and msg me.
If it's possible, great. As I alluded in the original post, having to do it manually for each executive isn't so bad. I'd still be curious to see how to do it programmatically; then I could pick and choose who to visit and who I could just send an email ;)
Thanks again,
T
_________________________________________________________________________________
I like computer programming because it's like Legos for the mind.
| [reply] |
Re: How to sync a UNC path to a USB memory stick in Windows?
by OfficeLinebacker (Chaplain) on May 31, 2006 at 22:30 UTC
|
UPDATE: After verifying that it works perfectly on my workstation, I tried it with my boss, and it doesn't work. More specifically: Creating the briefcase works fine, and copying stuff to it works fine. However, the "Update All" menu item does not appear in the context menu when right clicking. The only thing I can think of right now is that the actual memory sticks the execs use are secured via fingerprint scanning. My next step is to try to get a secured USB stick assigned to me, or get my boss to try it on my machine.
_________________________________________________________________________________
I like computer programming because it's like Legos for the mind.
| [reply] |
|
|
| [reply] |
|
|
Hey Browser!.
On my workstation, the context menu item appeared regardless of if there was updating to be done; I don't think it's like a daemon in that it constantly monitors the sync status. On my machine I could select 'Update All' and then after a short pause I would get a message that nothing had to be updated.
I am trying it right now on my work laptop here at home and getting the same problem (with a mapped drive to the same Samba share I was using for testing before). Am using a Kingston 512MB stick as opposed to some cheapie 64MB promotional stick I was using at work. Will update.
Thanks again,
T.
_________________________________________________________________________________
I like computer programming because it's like Legos for the mind.
| [reply] |
|
|
Re: How to sync a UNC path to a USB memory stick in Windows?
by OfficeLinebacker (Chaplain) on Jun 12, 2006 at 04:35 UTC
|
Greetings, esteemed monks!
Been a while. The Briefcase isn't quite working well. The Briefcase is designed to be a 2-way sync and it also seems to be reporting some files with identical modification times as both having been updated separately.
The main person who coordinates the source files is also leery of one of the users accidentally modifying the files on his stick. While the execs aren't supposed to be able to write back to the source stuff, she's a little leery of it as the permissions are tricky.
As a result, I've gone ahead and re-written something from scratch. I use File::Compare to be sure that the files are indeed different or identical. I eschew using the modificaiton date because this more cumbersome process will detect corruption in the mirrored data. However that's a lot of overhead. Is there another way I could do it at least as quickly and with the same robustness? For example I could check modification time FIRST (some files presumably would fail this quicker test and thus the contents comparison would be moot), and that way I would only be comparing the files that didn't really change, probably (which would still be the majority). Also, would something like an MD5 sum be a good way to check difference without reading every single one into memory (ie be 99.9% as robust but faster)? Here's my code so far:
use strict;
use File::Copy;
use File::Find;
use File::Compare;
my $source="G:\\contingency\\";
my $dest="D:\\";
(-r $source) || die "Error: $source not readable\n";
(-e $dest) || die "Error: $dest (memory stick) does not exist--is you
+r memory stick attached?\n";
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted{};
sub wanted2{};
my $newdirs;
my $newfiles;
my $changedfiles;
my $unchangedfiles;
my $orphans;
#Freshen up memory stick
my $status1=find(\&wanted,$source);
#..and then take care of orphans
my $status1=finddepth(\&wanted2,$dest);
my $totalfiles=$newdirs+$newfiles+$changedfiles+$unchangedfiles+$orpha
+ns;
print "Summary report: \n";
print "$totalfiles scanned.\n";
print "$newdirs new directories found and created.\n";
print "$newfiles new files found and copied.\n";
print "$changedfiles updated files copied.\n";
print "$unchangedfiles unchanged files ignored.\n";
print "$orphans orphans deleted from memory stick.\n";
sub wanted{
$dest=$name;
$dest =~ s/G:/D:/;
#sleep 3;
if (-d $name){
print "$name\n";
if ( not -e $dest){
print "Making directory $dest: \n";
mkdir $dest;
++$newdirs;
}
} else{
print "comparing $name to: \n$dest\n....\n";
my $status=compare($name, $dest);
#print "status of compare is $status.\n";
unless (!$status){
print "copying $name to memory stick \n($dest)\n......\n";
my $cstatus=copy($name, $dest);
#print "status of copy is $cstatus.\n";
#copy returns 1 on success
($cstatus) || die "Copy failed with status $cstatus: $!\n";
if ($status==-1){
print "File is new on contingency site since last update.\n(compar
+e returned $status: $!\n";
++$newfiles;
}else{
print "Version of file on memory stick was different(stale or alte
+red).\n";
++$changedfiles;
}
}else{
print "files are identical.\n";
++$unchangedfiles;
}
}
}
sub wanted2{
my $status=1;
$source=$name;
$source =~ s/D:/G:/;
if ( not -e $source){
++$orphans;
print "$name is an orphan";
if (-d $name){
$status=rmdir $name;
}else{
$status=unlink $name;
}
#rmidr returns true on success; unlink returns number of files del
+eted (should be 1)
($status) || warn "WARNING: Status of removal of $name is $status
+ : $!\n";
}
}
Thoughts?
T.
_________________________________________________________________________________
I like computer programming because it's like Legos for the mind.
| [reply] [d/l] |