Storypost | 2016.03.16
|
The .11 line is notorious for this problem, especially the 1.5TB version. The only HDDs I've had ever problems with were Seagate drives, and both were .11 drives. My issue was different - very high error counts which caused very poor performance from sector reallocation. That whole line was very problematic. |
package file_copy; import java.io.File; import java.io.FileOutputStream; import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Random; public class Main { public static void main(String args[]) { String dir = "[dir name]"; StringBuffer log = new StringBuffer(); // Define file locations. File destination_super = new File("[new dir]"); File source_super = new File("[old dir]"); File destination = new File(destination_super, dir); File source = new File(source_super, dir); if (!destination.exists()) { destination.mkdir(); } File last_file = null; int count = 0; // Keep track of files copied. int fails = 0; // Let a few failures occur before bailing. try { if (source.exists()) { // Randomize the files in the directory, this will avoid hitting // bad sectors repeatedly. Random random = new Random(); log.append("Running: " + source.getAbsolutePath() + " " + source.listFiles().length + " files\n"); List<File> files = new ArrayList<File>(); for (File file : source.listFiles()) { if (files.size() == 0) { files.add(file); } else { files.add(random.nextInt(files.size()), file); } } // Walk the randomized file list. for (File file : files) { File target = new File(destination, file.getName()); // Don't try to go deep, just inform user of a subdirectory. if (file.isDirectory()) { log.append("Skipped subdirectory: " + file.getAbsolutePath() + "\n"); } last_file = target; if (!target.exists()) { try { count++; Files.copy(Paths.get(file.getAbsolutePath()), Paths.get(target.getAbsolutePath())); } catch (Exception e) { log.append("Failed on " + last_file.getAbsolutePath() + "\n"); fails++; if (fails > 7) { throw e; } } } } log.append("Finished " + source.getAbsolutePath() + " " + source.listFiles().length + " files\n"); } else { log.append("Could not find: " + source.getAbsolutePath()); } } catch (Exception e) { log.append("Failed on " + last_file + " " + count + " completed\n"); log.append(e.getMessage()); } try { PrintWriter writer = new PrintWriter( new FileOutputStream(new File("C:\\data\\output.txt"))); writer.write(log.toString()); writer.close(); System.exit(0); } catch (Exception e) { System.exit(1); } } }
2016.04.03
All gamesThe Division, Broforce, and Helldivers |
2016.02.20
Moving earthA motorsports fan judges Monster Jam (and gets booed). Cities: Skylines, Helldivers, and Fallout 4. |
2020.02.11
WhistlerA ski trip to Whistler. |
blog.slaks.net
Writing the endraw tag in Jekyll code blocks - SLaks.Blog |
halleyscomment.blogspot.com
Halley's Comment: April 2002 |
tanelpoder.com
Do Not Use '>' in Your Command Prompt (and How to Stay Safe in Shell) | Tanel Poder ConsultingOver the years of troubleshooting performance problems in the Unix/Linux world, I have seen multiple cases where a regularly used command line tool in a customer server just stops working for some reason. The tool just returns immediately, doing absolutely nothing. No output printed, no coredumps and the exit code is zero (success!). This article walks you through a couple of such incidents and in the end I explain how I avoid accidentally doing bad stuff in production in general. - L... |