Custom Style All Your Form Elements with Pure CSS flpbd.it/vBBa2
Responsive Aeon Framework – 12Columns – Grid http:…
Responsive Aeon Framework – 12Columns – Grid flpbd.it/P1zbX
30 Free E-Commerce Icon Sets for Shopping Website…
30 Free E-Commerce Icon Sets for Shopping Website flpbd.it/kC6vk
Dan Grossman | A date range picker for Twitter Boo…
Dan Grossman | A date range picker for Twitter Bootstrap flpbd.it/i4Pr6
25 Web development tips to boost your skills http:…
25 Web development tips to boost your skills flpbd.it/UdfsN
zip files the groovy way
I’ve been told to perform some maintenace into one chaotic directory.
This directory stores about 225000 plain text files per month without any structure (yes I know, don’t ask). Try to do a simple ls into this directory after one year of files to realize that there is a problem.
We decided to create a monthly zip archive to store the files (based on it last modified date) while trying to explain the problem to the process «developer????»
Maybe you can do it with shell scripting , but I’ve chosen groovy.
There are a lot of improvements to do ( exception handling, validate parameters,… ), but it’s a starting point and worked fine for me. Feel free to change the script and share your improvements or comments.
Here is the script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import java.text.* import org.codehaus.groovy.runtime.TimeCategory import org.apache.tools.zip.ZipOutputStream import org.apache.tools.zip.ZipEntry //import org.apache.tools.tar.TarOutputStream //import org.apache.tools.tar.TarEntry //"2011-04-01" def startd = new SimpleDateFormat("yyyy-MM-dd").parse(args[0]) def endd = startd use(TimeCategory) { endd = startd + 1.month } println "Archiving files between $startd and $endd" def period = {file -> new Date(file.lastModified()) > startd && new Date(file.lastModified()) < endd } def thefiles = new File(args[1]).listFiles().toList().findAll(period) if( thefiles.size > 0 ){ ByteArrayOutputStream baos = new ByteArrayOutputStream() ZipOutputStream zipFile = new ZipOutputStream(baos) thefiles.each{ if( it.isFile() ){ zipFile.putNextEntry(new ZipEntry(it.name)) it.withInputStream { i -> zipFile << i } zipFile.closeEntry() } } zipFile.finish() def month = startd.format('yyyyMM') OutputStream outputStream = new FileOutputStream ( "${args[1]}/backup.${month}.zip" ) baos.writeTo(outputStream) thefiles.each{ it.delete() } println "${thefiles.size} files archived into ${args[1]}/backup.${month}.zip " }else{ println "No files found for given date " } |
To execute it, simply run
1 | groovy monthly_files.groovy 2012-07-01 /path/to/directory |
Specify as parameters the first day of month to process, and the path to the directory containing the files to archive.
If the amount of files is very large you’ll have to give more memory to the JVM
1 | export JAVA_OPTS="-Xmx2048m -XX:MaxPermSize=128m" |
Hope you find it useful
Esta semana 2012-10-14 en twitter
- Responsive jQuery Masonry · Osvaldas Valutis http://t.co/75XtpHlR #
- 15 Free HTML5-CSS3 Templates to Start the Future of Web Design | Blogfreakz – Web Design and Web Development resources http://t.co/4YxBVhRP #
- Ligature Symbols web font http://t.co/ji3HHeFI #
- Lo de @movistar_es no es normal 24 después de la instalación y ya con problemas de adsl #
- Esta semana 2012-10-07 en twitter http://t.co/wJveJEm8 #
- Esta semana 2012-10-07 en twitter http://t.co/LV8hlxqC #
- Esta semana 2012-10-07 en twitter http://t.co/x7w91hW5 #
Esta semana 2012-10-07 en twitter
- Ya estamos Preparados!! Hala Madrid! http://t.co/m2F4850n #
- Ser desarrollador de "apps" no sale rentable: la mayoría gana 500 dólares al mes http://t.co/pYA1pjWz #elconfidencial vía @elconfidencial #
- Simple and usefull
RT @emedinam: Grails Filter Tricks: Ajaxify Controller Actions – http://t.co/SIa5Vs6a # - 25 Sets Of Free Photoshop Tech Brushes For Your Futuristic Projects http://t.co/RbxJMCEA #
- 28 Free Vector Maps To Use In Your Projects http://t.co/AkUCmH1H #
- Excellent Easy To Use Flip (Flipboard Style) Transition Component | iOS Development Tips & Tricks by BiOM http://t.co/rTinsib8 #
- +1 “@ferrenet: Inditex +58% en Bolsa este año. http://t.co/7OpmMjeo¿No deberíamos votar a Amancio Ortega como Presidente del país? ;)” #
- PhotoAlbums de moleskine
http://t.co/4Qk1Nldq
Via @xatakafoto # - Blood http://t.co/9JwkTDpX #
- Inspiring UI Wireframe Sketches http://t.co/ehV7cpB8 #
- How to make the height of a GridView wrap its content http://t.co/y3fGqfGK #
- Esta semana 2012-10-03 en twitter http://t.co/Zyzk6ReA #
Esta semana 2012-10-03 en twitter
- Chillout http://t.co/kDMPbQOA #
- “Socialmatic” – La novedad de Instagram http://t.co/1y5nrNDE #
- Sublime Text 2 Project Bliss http://t.co/PuPYOPwG #
- 45 sites in black and white
http://t.co/wCfB0nEd # - Weekly Fresh Resources for Designers and Developers http://t.co/kzwwgAfp #
- KISS: A Showcase of Beautifully Simple Blog Design http://t.co/nisrrrRX #
- Base – A super simple, responsive framework designed to work for mobile devices, tablets, netbooks and desktop http://t.co/lsw6ACBu #
- Esta semana 2012-09-16 en twitter http://t.co/6HUtbuRC #
- Esta semana 2012-09-16 en twitter http://t.co/anuCcjwu #
- Esta semana 2012-09-16 en twitter http://t.co/c8rFHKt5 #
- Esta semana 2012-09-16 en twitter http://t.co/OUa55kfq #
Esta semana 2012-09-16 en twitter
- Let’s Make A Simple AJAX Note Taking App | Tutorialzine http://t.co/F3CKuNkC #
- +1 @TheGoOse @quesabesde, @Foto_Actualidad, @DSLRMagazine y otros Poned feeds RSS completos! Si queréis con publicidad, pero completos #
- Gallery of free HTML snippets for Twitter Bootstrap. | http://t.co/S56Wk12w http://t.co/8SHg8vTJ #twbootstrap via @bootsnipp #
- My monsters http://t.co/WD6lGj5n #
- Qedp http://t.co/nYLtPLrd #
- RT @Webdcrew: 25 Best Examples Of Business Card Designs | Ozone Eleven http://t.co/TK6ATC03 #
- 50 free Photoshop actions for portrait photographers http://t.co/27QyeT9W #
- Developing Backbone.js Applications http://t.co/DcqxJUsl #
- OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or a… by @weeUnquietMind on @slideshare http://t.co/s4QFSILC #
- BookBlock: A Content Flip Plugin | Codrops http://t.co/fiGgPn1I #
- Creative Web Typography Styles http://t.co/ss6FOIfi #
- Say Yo to Yeoman http://t.co/xRpIlbWq #
- Decorar imágenes con CSS 3 y HTML 5 – Parte 2 http://t.co/kstXbd0g #
- 45 Free and Fresh Web User Interface PSDs http://t.co/7SxqE263 #
- Websockets and Grails — Broadcasting to Topics | Compile Dammit!! http://t.co/3JTJPze6 #grails #
- bootstrap-wysihtml5 Simple, beautiful wysiwyg editor for twitter bootstrap http://t.co/12QSvAOc #
- 8 Useful Responsive CSS Frameworks http://t.co/MQc4JIfc #
- Collective #28 http://t.co/jHkAOapN #
- 22 JavaScript/jQuery Tutorials for New Web Developers http://t.co/oAGrkSL0 #
- 2 esquemas de fotografia de producto http://t.co/Vv8d7Nns #
- Batch Resizing Using Command Line and ImageMagick // Free Bash Script http://t.co/yTxOYrWS #
- Esta semana 2012-09-09 en twitter http://t.co/B3kGaJyo #
- Esta semana 2012-09-09 en twitter http://t.co/V60oAFd3 #