Attempt to save (recover) files from a broken external drive
My external drive that I use for Backup had some broken files. I feared that I'd lose some (or all) the data in there. So I wanted to copy each and every file to my hard disk.
I first tried using regular Windows methods (Copy, Xcopy). But, these methods took a lot of time and the commands would stop execution after hitting a broken file.
For example:
xcopy E:sampleSourceDirectory*.* D:BACKUPsampleSourceDirectory /s /e
Solution Method:
- An iterative script to try to move each file in the
sampleSourceDirectory
- Report how many files have failed
Note: I preferred MOVING files, instead of COPYING, so that I could retry moving the folder again, hoping that the external drive can read the files upon another trial.
Python script:
import shutil
import os
folderName = 'sampleSourceDirectory'
source = 'E:/' + folderName + '/'
destination = 'D:/BACKUP/' + folderName + '/'
if (os.path.exists(destination) == False):
os.makedirs(destination) #Make that Directory
files = os.listdir(source)
filesSource = files
nSuccess = 0 # number of Files
nFail = 0
while len(files)>0:
for f in files:
try:
shutil.move(source + f, destination + f)
nSuccess = nSuccess + 1
except OSError as err:
print("OS error: {0}".format(err))
files.remove(f)
nFail = nFail + 1
filesDestination = os.listdir(destination)
if (filesSource == filesDestination) and (len(filesSource) != 0):
print("Move Successful")
else:
print("ERROR IN MOVE!!! ****** CHECK WARNINGS!!! n")
print ( nFail, ' files failed!')
With this question, I'd like to first answer the basic question: is this an effective way to try saving files?
Secondly, I'd like to receive general feedback on the script itself, and any particular points that I might have misthought/misimplemented.
Final note: this script is not intended to be a secure way and I'd strongly advise not to use it for serious data. (I don't know if it's by chance or not but after a few trials my external drive stopped working completely, and I could only save 10% of the contents.)
python file-system windows
add a comment |
My external drive that I use for Backup had some broken files. I feared that I'd lose some (or all) the data in there. So I wanted to copy each and every file to my hard disk.
I first tried using regular Windows methods (Copy, Xcopy). But, these methods took a lot of time and the commands would stop execution after hitting a broken file.
For example:
xcopy E:sampleSourceDirectory*.* D:BACKUPsampleSourceDirectory /s /e
Solution Method:
- An iterative script to try to move each file in the
sampleSourceDirectory
- Report how many files have failed
Note: I preferred MOVING files, instead of COPYING, so that I could retry moving the folder again, hoping that the external drive can read the files upon another trial.
Python script:
import shutil
import os
folderName = 'sampleSourceDirectory'
source = 'E:/' + folderName + '/'
destination = 'D:/BACKUP/' + folderName + '/'
if (os.path.exists(destination) == False):
os.makedirs(destination) #Make that Directory
files = os.listdir(source)
filesSource = files
nSuccess = 0 # number of Files
nFail = 0
while len(files)>0:
for f in files:
try:
shutil.move(source + f, destination + f)
nSuccess = nSuccess + 1
except OSError as err:
print("OS error: {0}".format(err))
files.remove(f)
nFail = nFail + 1
filesDestination = os.listdir(destination)
if (filesSource == filesDestination) and (len(filesSource) != 0):
print("Move Successful")
else:
print("ERROR IN MOVE!!! ****** CHECK WARNINGS!!! n")
print ( nFail, ' files failed!')
With this question, I'd like to first answer the basic question: is this an effective way to try saving files?
Secondly, I'd like to receive general feedback on the script itself, and any particular points that I might have misthought/misimplemented.
Final note: this script is not intended to be a secure way and I'd strongly advise not to use it for serious data. (I don't know if it's by chance or not but after a few trials my external drive stopped working completely, and I could only save 10% of the contents.)
python file-system windows
1
My recommendation, if your filesystem might be broken: make a byte-for-byte clone of the filesystem before you do making any modifications to it that might worsen the situation.
– 200_success
Sep 19 at 18:58
@200_success thanks for the info and the link. I think I should take the safer route (as you mentioned). however I wanted to experiment with this idea and I had accepted losing some of the files on the way. It turned out to be a big loss (90% lost). I also tried using checkdisk to correct the file system; but it didn’t work. Btw, we had Norton disk doctor in the 90’s, to deal with such issues. Moving files may have really resulted in this mess. :(
– Gürkan Çetin
Sep 19 at 19:09
You should use ROBOCOPY not XCopy. All the issues you mention have switches to mitigate errors, verify CRC, only copy differences, etc.
– C. Harley
Sep 27 at 3:20
@C.Harley thank you, the drive is not responding as of now. :( so I cannot try.
– Gürkan Çetin
Sep 27 at 18:32
add a comment |
My external drive that I use for Backup had some broken files. I feared that I'd lose some (or all) the data in there. So I wanted to copy each and every file to my hard disk.
I first tried using regular Windows methods (Copy, Xcopy). But, these methods took a lot of time and the commands would stop execution after hitting a broken file.
For example:
xcopy E:sampleSourceDirectory*.* D:BACKUPsampleSourceDirectory /s /e
Solution Method:
- An iterative script to try to move each file in the
sampleSourceDirectory
- Report how many files have failed
Note: I preferred MOVING files, instead of COPYING, so that I could retry moving the folder again, hoping that the external drive can read the files upon another trial.
Python script:
import shutil
import os
folderName = 'sampleSourceDirectory'
source = 'E:/' + folderName + '/'
destination = 'D:/BACKUP/' + folderName + '/'
if (os.path.exists(destination) == False):
os.makedirs(destination) #Make that Directory
files = os.listdir(source)
filesSource = files
nSuccess = 0 # number of Files
nFail = 0
while len(files)>0:
for f in files:
try:
shutil.move(source + f, destination + f)
nSuccess = nSuccess + 1
except OSError as err:
print("OS error: {0}".format(err))
files.remove(f)
nFail = nFail + 1
filesDestination = os.listdir(destination)
if (filesSource == filesDestination) and (len(filesSource) != 0):
print("Move Successful")
else:
print("ERROR IN MOVE!!! ****** CHECK WARNINGS!!! n")
print ( nFail, ' files failed!')
With this question, I'd like to first answer the basic question: is this an effective way to try saving files?
Secondly, I'd like to receive general feedback on the script itself, and any particular points that I might have misthought/misimplemented.
Final note: this script is not intended to be a secure way and I'd strongly advise not to use it for serious data. (I don't know if it's by chance or not but after a few trials my external drive stopped working completely, and I could only save 10% of the contents.)
python file-system windows
My external drive that I use for Backup had some broken files. I feared that I'd lose some (or all) the data in there. So I wanted to copy each and every file to my hard disk.
I first tried using regular Windows methods (Copy, Xcopy). But, these methods took a lot of time and the commands would stop execution after hitting a broken file.
For example:
xcopy E:sampleSourceDirectory*.* D:BACKUPsampleSourceDirectory /s /e
Solution Method:
- An iterative script to try to move each file in the
sampleSourceDirectory
- Report how many files have failed
Note: I preferred MOVING files, instead of COPYING, so that I could retry moving the folder again, hoping that the external drive can read the files upon another trial.
Python script:
import shutil
import os
folderName = 'sampleSourceDirectory'
source = 'E:/' + folderName + '/'
destination = 'D:/BACKUP/' + folderName + '/'
if (os.path.exists(destination) == False):
os.makedirs(destination) #Make that Directory
files = os.listdir(source)
filesSource = files
nSuccess = 0 # number of Files
nFail = 0
while len(files)>0:
for f in files:
try:
shutil.move(source + f, destination + f)
nSuccess = nSuccess + 1
except OSError as err:
print("OS error: {0}".format(err))
files.remove(f)
nFail = nFail + 1
filesDestination = os.listdir(destination)
if (filesSource == filesDestination) and (len(filesSource) != 0):
print("Move Successful")
else:
print("ERROR IN MOVE!!! ****** CHECK WARNINGS!!! n")
print ( nFail, ' files failed!')
With this question, I'd like to first answer the basic question: is this an effective way to try saving files?
Secondly, I'd like to receive general feedback on the script itself, and any particular points that I might have misthought/misimplemented.
Final note: this script is not intended to be a secure way and I'd strongly advise not to use it for serious data. (I don't know if it's by chance or not but after a few trials my external drive stopped working completely, and I could only save 10% of the contents.)
python file-system windows
python file-system windows
edited 16 mins ago
Jamal♦
30.2k11116226
30.2k11116226
asked Sep 19 at 18:36
Gürkan Çetin
20719
20719
1
My recommendation, if your filesystem might be broken: make a byte-for-byte clone of the filesystem before you do making any modifications to it that might worsen the situation.
– 200_success
Sep 19 at 18:58
@200_success thanks for the info and the link. I think I should take the safer route (as you mentioned). however I wanted to experiment with this idea and I had accepted losing some of the files on the way. It turned out to be a big loss (90% lost). I also tried using checkdisk to correct the file system; but it didn’t work. Btw, we had Norton disk doctor in the 90’s, to deal with such issues. Moving files may have really resulted in this mess. :(
– Gürkan Çetin
Sep 19 at 19:09
You should use ROBOCOPY not XCopy. All the issues you mention have switches to mitigate errors, verify CRC, only copy differences, etc.
– C. Harley
Sep 27 at 3:20
@C.Harley thank you, the drive is not responding as of now. :( so I cannot try.
– Gürkan Çetin
Sep 27 at 18:32
add a comment |
1
My recommendation, if your filesystem might be broken: make a byte-for-byte clone of the filesystem before you do making any modifications to it that might worsen the situation.
– 200_success
Sep 19 at 18:58
@200_success thanks for the info and the link. I think I should take the safer route (as you mentioned). however I wanted to experiment with this idea and I had accepted losing some of the files on the way. It turned out to be a big loss (90% lost). I also tried using checkdisk to correct the file system; but it didn’t work. Btw, we had Norton disk doctor in the 90’s, to deal with such issues. Moving files may have really resulted in this mess. :(
– Gürkan Çetin
Sep 19 at 19:09
You should use ROBOCOPY not XCopy. All the issues you mention have switches to mitigate errors, verify CRC, only copy differences, etc.
– C. Harley
Sep 27 at 3:20
@C.Harley thank you, the drive is not responding as of now. :( so I cannot try.
– Gürkan Çetin
Sep 27 at 18:32
1
1
My recommendation, if your filesystem might be broken: make a byte-for-byte clone of the filesystem before you do making any modifications to it that might worsen the situation.
– 200_success
Sep 19 at 18:58
My recommendation, if your filesystem might be broken: make a byte-for-byte clone of the filesystem before you do making any modifications to it that might worsen the situation.
– 200_success
Sep 19 at 18:58
@200_success thanks for the info and the link. I think I should take the safer route (as you mentioned). however I wanted to experiment with this idea and I had accepted losing some of the files on the way. It turned out to be a big loss (90% lost). I also tried using checkdisk to correct the file system; but it didn’t work. Btw, we had Norton disk doctor in the 90’s, to deal with such issues. Moving files may have really resulted in this mess. :(
– Gürkan Çetin
Sep 19 at 19:09
@200_success thanks for the info and the link. I think I should take the safer route (as you mentioned). however I wanted to experiment with this idea and I had accepted losing some of the files on the way. It turned out to be a big loss (90% lost). I also tried using checkdisk to correct the file system; but it didn’t work. Btw, we had Norton disk doctor in the 90’s, to deal with such issues. Moving files may have really resulted in this mess. :(
– Gürkan Çetin
Sep 19 at 19:09
You should use ROBOCOPY not XCopy. All the issues you mention have switches to mitigate errors, verify CRC, only copy differences, etc.
– C. Harley
Sep 27 at 3:20
You should use ROBOCOPY not XCopy. All the issues you mention have switches to mitigate errors, verify CRC, only copy differences, etc.
– C. Harley
Sep 27 at 3:20
@C.Harley thank you, the drive is not responding as of now. :( so I cannot try.
– Gürkan Çetin
Sep 27 at 18:32
@C.Harley thank you, the drive is not responding as of now. :( so I cannot try.
– Gürkan Çetin
Sep 27 at 18:32
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f204005%2fattempt-to-save-recover-files-from-a-broken-external-drive%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f204005%2fattempt-to-save-recover-files-from-a-broken-external-drive%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
My recommendation, if your filesystem might be broken: make a byte-for-byte clone of the filesystem before you do making any modifications to it that might worsen the situation.
– 200_success
Sep 19 at 18:58
@200_success thanks for the info and the link. I think I should take the safer route (as you mentioned). however I wanted to experiment with this idea and I had accepted losing some of the files on the way. It turned out to be a big loss (90% lost). I also tried using checkdisk to correct the file system; but it didn’t work. Btw, we had Norton disk doctor in the 90’s, to deal with such issues. Moving files may have really resulted in this mess. :(
– Gürkan Çetin
Sep 19 at 19:09
You should use ROBOCOPY not XCopy. All the issues you mention have switches to mitigate errors, verify CRC, only copy differences, etc.
– C. Harley
Sep 27 at 3:20
@C.Harley thank you, the drive is not responding as of now. :( so I cannot try.
– Gürkan Çetin
Sep 27 at 18:32