Question: Undo a shell script when input file is overwritten
0
gravatar for rse
9 days ago by
rse70
Singapore
rse70 wrote:

Hi,

Is it possible to redo a shell script? I overwrote my files running a shell script

I ran nohup sh 1.sh
But my output file was same as the input file, so it overwrote my input file

Thank you

next-gen • 201 views
ADD COMMENTlink modified 8 days ago • written 9 days ago by rse70

Changed the title to make it more specific, added the additional information provided in the comments to the original question, cleaned up comments, and moved comments to answer so you can mark them as accepted.

ADD REPLYlink written 9 days ago by WouterDeCoster38k

Thank you for your help. I don't have backup of file but i am still optimistic. I used zcat and gzip to merge and zip the files using : zcat file1.fastq.gz file2.fastq.gz | gzip -c > file1.fastq.gz

ADD REPLYlink written 8 days ago by rse70
2

You could just do cat file1.fastq.gz file2.fastq.gz > merged.fastq.gz. There is no need to zcat/gzip again.

ADD REPLYlink written 8 days ago by WouterDeCoster38k

zcat already concatanates compressed files, there is no need for gzip in this command:

zcat file1.fastq.gz file2.fastq.gz > file1.fastq.gz
ADD REPLYlink modified 8 days ago • written 8 days ago by ATpoint15k

Ok, thanks. But my file1.gz is empty now

ADD REPLYlink written 8 days ago by rse70

I found this link : https://superuser.com/questions/292728/critical-gzip-mistake-help-how-to-undo-gzip-r/1426042#1426042 Will gzip -r work? Thanks

ADD REPLYlink written 8 days ago by rse70

Sorry, did not pay attention. Use cat to concatenate:

cat file1.fastq.gz file2.fastq.gz > new.fastq.gz

Also do not write to a file with identical name as the input.

ADD REPLYlink modified 8 days ago • written 8 days ago by ATpoint15k
0
gravatar for Carambakaracho
9 days ago by
Carambakaracho1.0k
Switzerland/Basel
Carambakaracho1.0k wrote:
  • restore input from backup
  • recompute input

there's not much else you can do... sooner or later, that happens to everybody

ADD COMMENTlink modified 9 days ago • written 9 days ago by Carambakaracho1.0k
2
rm * .bam
ADD REPLYlink written 9 days ago by ATpoint15k

Lol...don't want to delete more files

ADD REPLYlink written 8 days ago by rse70
0
gravatar for WouterDeCoster
9 days ago by
Belgium
WouterDeCoster38k wrote:

Your input file is gone. Unless you have a backup somewhere, there is no way to restore it or "redo" the script.

Pro tip: make sure your input files are read-only (chmod -w) to avoid loss of data.

ADD COMMENTlink modified 8 days ago • written 9 days ago by WouterDeCoster38k

You mean chmod -w, no?

ADD REPLYlink written 8 days ago by RamRS21k

Certainly! Will change my post.

ADD REPLYlink written 8 days ago by WouterDeCoster38k
0
gravatar for jrj.healey
9 days ago by
jrj.healey12k
United Kingdom
jrj.healey12k wrote:

As others have said, your data is long gone, unless:

  • You have the original input data, and can simply recompute it easily enough.
  • Your server/SysAdmin has configured regular snapshots, but this isn't that common, and would probably only get you to whereever you were yesterday.

There's no such thing as a recycle bin on Unix, so when you delete stuff - you really delete stuff.

ADD COMMENTlink written 9 days ago by jrj.healey12k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1801 users visited in the last hour