G+_Dan Sarauer (N3m1sys) Posted August 15, 2014 Share Posted August 15, 2014 Looking for a good way to use Perl (or any other language I guess) to recursively archive some files/folders based on date modified while keeping the folder structure in-tact. I've looked at File::Copy::Recursive in CPAN and it looks promising, but I haven't wrapped my head around getting it to check the files date modified before just copying the whole lot. Ideas code monkeys? Link to comment Share on other sites More sharing options...
G+_Dudley Adams Posted August 15, 2014 Share Posted August 15, 2014 Two ways to tackle this problem come to my mind: 1. Just use rsync. 2. Use File::Find. Here's a snippet of what that might look like: #!/usr/bin/perl use warnings; use File::Find; my @dirs_to_search= qw{/usr/local/bin /usr/share /etc /var/www}; use constant TIME_THRESHHOLD => 7; find(\&wanted,@dirs_to_search); sub wanted { (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($)) && int(-M _) > TIME_THRESHHOLD && archive_this($); } sub archive_this { # Archiving logic goes here } Link to comment Share on other sites More sharing options...
G+_Travis Hershberger Posted August 15, 2014 Share Posted August 15, 2014 What OS are you using? BASH in UNIX/Linux world can do this easily, Windows should be able to as well I just wouldn't be able to guess how to do it off the top of my head. Link to comment Share on other sites More sharing options...
G+_Dan Sarauer (N3m1sys) Posted August 15, 2014 Author Share Posted August 15, 2014 Unfortunately we have a windows environment. I don't prefer it, but what are you gonna do? Link to comment Share on other sites More sharing options...
G+_Travis Hershberger Posted August 15, 2014 Share Posted August 15, 2014 Install Cygwin? Sorry, I'm not remember how to search for files based on the date/timestamp in Windows. Link to comment Share on other sites More sharing options...
G+_Matthew Reardon Posted August 16, 2014 Share Posted August 16, 2014 Daniel: As a noob I am not sure of best way. Perhaps a python script that uses os.walk to go through directories and then uses os.path.getmtime to determine which files to copy. (http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python) Matt Link to comment Share on other sites More sharing options...
G+_Joe Maruschek Posted August 16, 2014 Share Posted August 16, 2014 I suggest taking a look at the good old XCOPY command: http://technet.microsoft.com/en-us/library/cc771254.aspx I thin you will find the /d and /s parameters useful. Link to comment Share on other sites More sharing options...
G+_Dan Sarauer (N3m1sys) Posted August 19, 2014 Author Share Posted August 19, 2014 XCopy could work nicely if it had the option to delete the file after a successful copy. Link to comment Share on other sites More sharing options...
G+_mightymaan Posted August 24, 2014 Share Posted August 24, 2014 Windows environment? Really powershell is your only real choice. Vbscipt too but many, many more lines Link to comment Share on other sites More sharing options...
G+_Razelda Peacecraft Posted September 12, 2014 Share Posted September 12, 2014 you can use xxcopy with a batch file or if you are using linux systems you can just us cp with a bash script ... xxcopy is grate a recursively copying or moving files you just need to know what switch you whant to use Link to comment Share on other sites More sharing options...
Recommended Posts