Difference between revisions of "Recovering crashes manually"

From Audacity Wiki
Jump to: navigation, search
m (Other Tools / scripts: trim of unnecessary stuff)
(deprecated the page, removed the P206 - left a redirect for existing links to this page that may exist on the Forum)
Line 1: Line 1:
{{ednote|'''Gale 05May14:''' We link to this page almost every day on the Forum for users who have lost the AUP file through their own fault, system crash or Audacity error. I did a rough revamp for 2.x. <p> Ideally this page should have the revamp fully completed then be moved to the Manual, but most users who try the steps here do succeed, so it is not a priority to make changes. </p>
{{advice|This page has been transferred to the Audacity Manual - see [http://manual.audacityteam.org/man/Recovering_crashes_manually Recovering Crashes Manually] in the Audacity Manual.}}
*'''Peter 8Jun14:''' [[ToDo-206]] this page can be deleted once 2.0.6 is released.  Since it is in daily use I decided to copy it to the alpha Manual straight away.  Updates can, and should, be made there - the P2 for this was transferred to the [http://manual.audacityteam.org/man/Crash_recovery new Manual page]. }}
{{intro|If Audacity crashes or the computer loses power, Audacity should normally [http://manual.audacityteam.org/o/man/recovery.html recover the projects automatically] when you restart.| Only use these manual recovery steps if automatic recovery does not work correctly or if you have no usable AUP file to go back to.}}
{{alert|'''If the Automatic Crash Recovery dialogue has appeared but recovery is incorrect, do not close Audacity or save any changes until manual recovery using these instructions is complete.''' <p>If you need to shut down the computer before manually fixing an incorrect Automatic Crash Recovery, force quit Audacity in the system task manager. This will preserve the temporary data for next launch of Audacity.</p>}}
If you have the AUP project file, open it to return the last saved state of the project. If the last saved state was a new, empty project, or if you don't have an AUP project file, you can recover the audio from the project's _data folder or Audacity's temporary folder by one of the manual or automatic methods below.
The _data folder will be in the same directory as the AUP file.
== Location of Temporary Folder ==
This is only relevant if you never saved a project and have no usable AUP file or AUTOSAVE file.
{{hint|1=On Mac computers, the temporary folder is usually hidden in the Finder.  To access it, use the '''"Go To Folder"''' command in the Finder, or type <span style="color:#FA58AC;font-size:118%">open tmp/ </span> and insert the name of the folder after the <span style="color:#FA58AC;font-size:118%"> / </span>. If that doesn't work, try to make the Finder show its hidden files and folders by entering the following commands in the terminal:<span style="color:#FA58AC;font-size:118%">
:defaults write com.apple.finder AppleShowAllFiles TRUE
:killall Finder
</span> then relaunch Finder to show the hidden files. Alternatively, try [http://macupdate.com/info.php/id/5721 TinkerTool] to do the same thing, or on OS X 10.6 or later you can type Shift-Command-Period(.) to show or hide hidden files and folders in an Open or Save dialogue.}}
== Manual recovery ==
If you only have a few AU files to recover, use the "Import Audio" command to open all the .au files from the Audacity temporary folder or project _data folder.  Use shift-click or control-click to select multiple files.  The files will be in approximately 6-second chunks and will be on separate tracks in the Audacity screen.  Files from stereo tracks will alternate between left and right channels. 
#Click in the Track Control Panel (by the Mute/Solo buttons) of the topmost track.
# Z or {{menu|Edit > Find Zero Crossings}}.
# {{menu|Edit > Remove Audio or Labels > Trim}}.
#Click in the Track Control Panel of the first track you want to join to the topmost track.
# Z or {{menu|Edit > Find Zero Crossings}}.
#Click {{menu|Edit > Remove Audio or Labels > Cut}}.
#Click after the end of the topmost track.
#Press {{shortcut|END}} on the keyboard.
#Click {{menu|Edit > Paste}} and the cut track will attach to the end of the topmost track.
#Repeat as necessary to join all the tracks onto the topmost track.
Play the result.
Cut and paste as needed if any files are found to be in the wrong order or the wrong channel.   
==Automatic recovery tools==
Tools written for legacy Audacity 1.2 can automate data recovery.
{{advice|All these utilities require the .au files to be input in consecutive alphanumerical order. Audacity names files randomly so files will need to renamed.}}
Open Audacity's temporary or project _data folder in your system file manager. Sort the files by timestamp order (earliest first), then rename them using a consecutive alphanumerical sequence, lowest number first. An arrangement looking something like this should work:
::b001.au 15:56:02
::b002.au 15:56:02
::b003.au 15:56:10
::b004.au 15:56:10
{{Hint|1='''Utilities for renaming files to consecutive alphanumerical order'''
<ul><li>On '''Windows,''' Explorer cannot rename to a sequence acceptable to the recovery tools. You can use instead the Mass Rename tool in the freeware [http://www.zabkat.com/x2lite.htm xplorer<sup>2</sup>lite] file manager.
<ol><li> Open the required folder in xplorer<font size="-2"><sup>2</sup></font> and sort the .au files by time modified as above
<li>{{Menu|CTRL + A}} to select all the files
<li> File > Mass Rename
<li> In the "Mass Rename Wizard", click in "Target name template" and type the letter '''e''' with a '''$''' after the letter. For example, '''e$0001.au''' will rename the files to e0001.au, e0002.au and so on. Use enough zeros in the filename so that all the .au files will have the same number of digits.
<li> Press "Preview", and if the preview looks correct, hit "Rename"</ol>
<li>On '''Mac OS X''', try Applications > [http://www.macosxautomation.com/automator/ Automator].
<li>On '''Linux''', try the file manager [http://en.wikipedia.org/wiki/Thunar Thunar] included in the [http://xfce.org/ xfce desktop] See [http://www.ubuntugeek.com/switch-to-a-lightweight-filemanager.html here] for help running Thunar on the Ubuntu desktop.
{{note|1='''Linux command-line alternatives for time stamp sorting'''
<ol><li>Open a terminal then "cd" into the directory that contains the .AU files.
<li> Type the following command in a terminal to sort and rename the files into numerical time stamp order:<br>
'''<nowiki>mkdir "renamed" | find -type f -name "*.au" -printf "cp %h/%f renamed/%h/%TY%Tm%Td-%TH%TM%TS_%f\n"|sh</nowiki>'''
<li>The file names produced in the "renamed" folder are '''not''' in a consecutive sequence suitable for the Audacity recovery utilities. Instead, use the [[Nyquist Plug-ins|Nyquist]] plug-in [http://forum.audacityteam.org/viewtopic.php?f=42&t=59528 Append Import] to import the files end-to-end into Audacity automatically in file name order. 
<div id="limitations"></div> 
=== Limitations of automatic recovery utilities ===
*There is a '''2 GB maximum size for any WAV file created from the reconstructed temporary files'''. This implies no more than 2000 .au files can be recovered. Sometimes (probably due to bugs in the utilities) there can be errors when recovering only 1000 or so files. In that case you would need to split the .au files in the temporary or_data folder into two or more folders, each containing consecutively numbered files, and recover a separate WAV file from each folder. 
* Recovery of unedited mono recordings made in Audacity 1.2 and later Audacity should be correct in most cases. 
* Recovery of unedited stereo recordings made in Audacity 1.2 should be correct in most cases. Unedited stereo recordings made in later Audacity may recover with transposed left/right channels in places. This is because the files for each channel may have time stamps that are too close together to be correctly distinguished by the operating system. 
* If any of the project data has been edited, it is unlikely to recover correctly.
=== 1.2 Audacity Recovery Utility ===
The 1.2 Audacity Recovery Utility assumes the project rate was 44100 Hz. If your project was at other than 44100 Hz, the recovered WAV file will be the wrong length and play at the wrong speed. To correct this after importing the recovery WAV file, click in the name of the track (by the downward-pointing arrow) then use "Set Rate" to choose the correct rate.
'''Windows and Linux'''
Follow the instructions on the [http://www.mesw.de/audacity/recovery/ Audacity Recovery Utility] page. On Linux, you may need to install additional libraries before you can use the utility, following the instructions provided.
Download the following utilities instead which are ready-compiled with the necessary libraries:
*[http://www.gaclrecords.org.uk/audacity_recovery_osx_ppc.zip for Power PCs]
*[http://www.gaclrecords.org.uk/audacity_recovery_osx_intel.zip for Intel Macs]
Then follow the instructions on the [http://www.mesw.de/audacity/recovery/ Audacity Recovery Utility] page from "About the Audacity Recovery Utility" onwards.
=== Aud_Recover command-line recovery utility ===
This is a portable command line program for Audacity 1.2 by Tyler Knott which does much the same as the Audacity Recovery Utility but is not written in python/ wxpython, so does not need those libraries in order to compile it.  Due to limitations in the C standard library this program cannot create files larger than 2 GB.
You can download aud_recover version 1.1.1 [http://2by2.info/aud_recover-1.1.1.zip here].  This download contains binaries for Windows (32-bit) and the cross-platform C source code.
To recover files using this program:
#Find the first and last files in the recording by listening to them (if you've only done one recording then that should be the first and the last files in the directory).
#Place the aud_recover program in your Audacity temp directory
#*aud_recover requires several settings to run.  You can either enter them as command-line options (use --help for more information) or interactively by simply running the program. Make sure you enter the name of both the first and last file as a number without leading zeros (for example, "b00001.au" should be entered as "1").
#*aud_recover will generate one or more files (depending on how many channels of audio you recorded, usually one for mono and two for stereo).  Import these into Audacity using the Import Raw Data option.  To configure the dialog, follow these directions:
#You can determine the sample format (the first drop-down) and the endianness (the second) using the included auinfo.exe. To do this, enter the full file name of one of the original files, for example "b00001.au" (without quotes). 
#*The header offset should be zero and the amount to import should be 100%.  No matter how many channels were recorded you should keep it set to 1 (see the next numbered step).
#*The sample rate should be set to the sample rate you recorded at (the sample rate given by auinfo is always 44100, even if that is incorrect, due to a bug in Audacity).
#*Repeat this step for every output file.
#For stereo files set the left channel to left, the right channel to right, then select "Make Stereo Track" from the track dropdown menu to convert it to a stereo track.
The resulting track should be exactly what was recorded before Audacity crashed.
If you have any questions, comments, or bug reports please don't hesitate to [mailto:[email protected]?subject=Aud_Recover email me] (tknott _at_gmail_dot_com).
=== audacity_rescue.sh ===
This shell script was created after a crash in order to reassemble a few thousand .au files. It is not perfect but may be simpler to apply (at a bash terminal) than some of the solutions mentioned on this page, particularly for mono recordings.
[https://gist.github.com/912222 https://gist.github.com/912222]
''If there is interest in a general purpose tool I am happy to develop it - [http://dylan-evans.github.com/2011/04/11/audacity-rescue.html Let me know]''
== Other Tools / scripts ==
This freeware tool can automatically join large numbers of files.  (Note: One Audacity user reported an audible noise at the places where the files were joined.)
* [http://123-audio-video-merger.softpedia.com/ 123 Audio Video Merger]
* tail and cat (On Linux/UNIX systems)
    - I found that 123 AV Merger gave me exactly what I would get with cat.
    I  was able to get around this with the following procedure:
    1. I had to throw out all odd-numbered files (1,3,5...)
    2. Using tail's byte-count switch "-c" I copied each remaining .au to a new .au.tmp file
    3. Using cat I  ran all the .au.tmp files into on long .au
    4. Imported the final .au with "Import RAW Data"
    5. Exported the track as wav
    I played around with exactly how many bytes to tail until there was no longer any sharp noises at each joint.
[http://sox.sourceforge.net/ SoX] can concatenate the files together.
Usage: sox file-1 file-2 ... file-n outfile
(SoX can handle up to 32 files at a time.)
e.g. for a mono recording:
  % sox b0000*.au b0001*.au b0002*.au junk0.au
After I'm done, I have just several au files to import (a lot fewer than before).
I created a hard-link backup of a directory full of 256 files named e00039df.au etc. with names that did not correspond to modification times, then used SoX:
  % cp -la d00 d00.bak
  % cd d00
  % mv `ls --full-time e*.au|sort|head -n1|cut -d ' ' -f 9` 0.au
  % counter=0
  % while [ `ls e*.au|head -n1` ]; do
  >sox ${counter}.au `ls --full-time e*.au|sort|head -n30|cut -d ' ' -f 9` $[counter+1].au
  >rm -f `ls --full-time e*.au|sort|head -n30|cut -d ' ' -f 9` ${counter}.au
  >let counter=$[counter+1]
When the operation was completed, I moved the resulting .au file to the next directory full of files (d01 in this case) and renamed it to 0.au, then ran again:
  % counter=0
  % while [ `ls e*.au|head -n1` ]; do
  >sox ${counter}.au `ls --full-time e*.au|sort|head -n30|cut -d ' ' -f 9` $[counter+1].au
  >rm -f `ls --full-time e*.au|sort|head -n30|cut -d ' ' -f 9` ${counter}.au
  >let counter=$[counter+1]
rinsed & repeated for 4 directories with a total of 1.2GB
I found it easier to write the following Python script that I used under Mac OS X to recover 1.2GB of data.  It was easier than the above solutions.
% cat recover.py
# python script to recover audacity recording after crash
import os
directory = raw_input('Enter directory where temp data files are: ')
rawfiles = os.listdir(directory)  # grab directory listing
files = []          # only interested in .au files and
for i in rawfiles:  # prepend each with the directory name
  if i[-3:] == '.au': files.append(directory+'/'+i)
files.sort()  # sort files so the result will be in proper sequence
# open the output file for the recovery
fp = open('recover.au','wb')
# write the whole first file because it has the header
dd = open(files[0],'rb').read()
# for every other file, write from the data offset on
for i in files[1:]:
  dd = open(i, 'rb').read()[12380:]
# close recovered sound file
I had problems using the above script.  I found that it didn't really write every other file, so if you try to recovery stereo recordings you get a nasty echo effect since every other file is the left or right channel.
<i>The problem with the script above is that you coded the slice wrong:
>>> x=(1,2,3,4,5,6,7,8,9,10)  # sample data
>>> x[1:]                    # doesn't do what you wanted
(2, 3, 4, 5, 6, 7, 8, 9, 10)
>>> x[::2]                    # this gets the odd-numbered items
(1, 3, 5, 7, 9)
>>> x[1::2]                  # this gets the even-numbered ones
(2, 4, 6, 8, 10)
So, you just need to change the line "for i in files[1:]:" to either "for i in files[::2]:" (for the first channel), or "for i in files[1::2]:" (for the other).</i>
I wrote this modified version of the script to try to put the two tracks into two recovery files.  Unfortunately, just importing the recovered files doesn't seem to give you perfect stereo again because of sync issues, possibly due to missing files in the recovery set.  Give it a shot, it might work for you.
# python script to recover audacity recording after crash
import os
directory = raw_input('Enter directory where temp data files are: ')
rawfiles = os.listdir(directory)  # grab directory listing
files = []          # only interested in .au files and
for i in rawfiles:  # prepend each with the directory name
  if i[-3:] == '.au': files.append(directory+'/'+i)
files.sort()  # sort files so the result will be in proper sequence
# open the output file for the recovery
fp = open('recover.au','wb')
# write the whole first file because it has the header
dd = open(files[0],'rb').read()
#this is intented for recoverying stereo and the second file should be the
# first part of the second track, so write the whole file.
fpp = open('recover2.au','wb')
# write the whole second file because it has the header for track 2
dd = open(files[1],'rb').read()
#it's stereo, so the .au files should alternate left & right channels, so files
#should be written to our two recovery files alternately starting with the 3rd file in our list
#count serves as a quick hack to let us alternate recovery files
count = 1
#this is just to give a quick count so you can see if the two recovery files got the same number of files added to them
track_one_files = 1
track_two_files = 1
# for every other file, write from the data offset on
for i in files[2:]:
  if count == 1:
#write to first recovery file
  dd = open(i, 'rb').read()[12380:]
  count = 0
track_one_files = track_one_files + 1
#write to second recovery file
dd = open(i, 'rb').read()[12380:]
count = 1
track_two_files = track_two_files + 1
print "Files recovered for track 1:"
print track_one_files
print "Files recovered for track 2:"
print track_two_files
# close recovered sound files
I was unable to get SoX to work as the above tip instructed.  SoX always complained about a missing operation or misinterpreted the filename of one of the Audacity temp files as a filter to perform on the other files.
So, I used SoX in a different way.  I was trying to rescue an hour-long mono recording on a Unix-like system (a Fedora Core 3 GNU/Linux system).  First, I made a copy of the temp directory and its files:
$ cp -r /tmp/audacity1.2-jbn ~/rescue
Then I used SoX to convert the AU temp files into raw files (headerless files).  Since Audacity had already numbered the files with leading zeroes (and perhaps because I didn't have that many of them to work on), I could use an ordinary shell wildcard to do the work:
$ for f in b*.au ; do sox ${f} -t raw ${f}.raw ; done
I concatenated the raw files together to make one hour-long mono raw file.  I had to use raw files to do this, concatenating the AU files together (each with its own header) would have produced a periodic noise (because Audacity was trying to interpret the AU header data as sound data).
$ cat *.raw > bigfile.raw
And then I imported the raw file into Audacity specifying the appropriate number and signedness of the samples (16-bit signed PCM, in my case), endianness (Big-endian, in my case), channels (1 channel for mono), and sample rate (44,100 samples per second, in my case).  I wanted to import the whole file (100%) starting from the beginning (0 byte offset).
I was left with a file I could export to WAV, play, and edit normally.
i tried to add the .au files to a winamp playlist ordered by date (ascending)
then save the output as a wav file
this solved my problem. i hope it will help yours.
(My project was a recording project so the order of files were easily understood)
I also had success with the winamp method using the write to disk output utility.  Didn't work for me until I first converted each individual .au into .wav files then converted all the .wav files into a single .wav file.
Yet another way to do it, this time with perl:
use strict;
use warnings;
my $limit = 32; # Sox can only read this many files at a time
my @files = <*.au>;
my $count = 0;
while (my $set = join ' ',splice @files,0,$limit) {
    my $cmd = "sox $set recovered_$count.au";
    unlink "recovered_" . ($count - 1) . ".au" if $count;
    if (@files) {
        unshift @files,"recovered_$count.au";
    } else {
        rename "recovered_$count.au","recovered.au";
Run this in a directory full of .au's...

Revision as of 08:57, 30 September 2014

Warning icon This page has been transferred to the Audacity Manual - see Recovering Crashes Manually in the Audacity Manual.