Database accidentally deleted with a bash scriptMonday morning mistake: sudo rm -rf --no-preserve-root /Accidentally formated external usb harddrive (500GB) with bootable iso (1GB), how can I recover my data?What is the difference between double and single square brackets in bash?How to add a timestamp to bash script log?Large incremental backup sizes although minimal changes with cPanel tarballsZPOOL replace defective disk in exported poolUbuntu OS recovery – accidentally deleted ld-linux-x86-64.so.2 from /lib64 folder in Ubuntu 14.04What is the best way to restore ubuntu on a new server with SSD hd and RAID?Decode & restore files from /dev/md3 (Hacked server)Synology: How to restore data from an accidentally deleted volumeX (BTRFS)?Mapped VMDK no longer accessible - VMware ESX - recover data

Bob has never been a M before

Is there a conventional notation or name for the slip angle?

Diode in opposite direction?

Filling the middle of a torus in Tikz

How can "mimic phobia" be cured or prevented?

Proving a function is onto where f(x)=|x|.

Did US corporations pay demonstrators in the German demonstrations against article 13?

Does a 'pending' US visa application constitute a denial?

Could the E-bike drivetrain wear down till needing replacement after 400 km?

How much character growth crosses the line into breaking the character

Can we have a perfect cadence in a minor key?

Engineer refusing to file/disclose patents

Translation of Scottish 16th century church stained glass

What is the gram­mat­i­cal term for “‑ed” words like these?

Query about absorption line spectra

Folder comparison

Why do IPv6 unique local addresses have to have a /48 prefix?

MAXDOP Settings for SQL Server 2014

Can the Supreme Court overturn an impeachment?

Create all possible words using a set or letters

How to set Output path correctly for a Single Image render?

Should spaces be used when writing foreign names in katakana?

Do Legal Documents Require Signing In Standard Pen Colors?

Is it possible to have a strip of cold climate in the middle of a planet?



Database accidentally deleted with a bash script


Monday morning mistake: sudo rm -rf --no-preserve-root /Accidentally formated external usb harddrive (500GB) with bootable iso (1GB), how can I recover my data?What is the difference between double and single square brackets in bash?How to add a timestamp to bash script log?Large incremental backup sizes although minimal changes with cPanel tarballsZPOOL replace defective disk in exported poolUbuntu OS recovery – accidentally deleted ld-linux-x86-64.so.2 from /lib64 folder in Ubuntu 14.04What is the best way to restore ubuntu on a new server with SSD hd and RAID?Decode & restore files from /dev/md3 (Hacked server)Synology: How to restore data from an accidentally deleted volumeX (BTRFS)?Mapped VMDK no longer accessible - VMware ESX - recover data













7















My developer committed a huge mistake and we cannot find our Mongo database anywhere in the server.



He logged into the server, and saved the following shell under ~/crontab/mongod_back.sh:



mongod_back.sh



#!/bin/sh
DUMP=mongodump
OUT_DIR=/data/backup/mongod/tmp // 备份文件临时目录
TAR_DIR=/data/backup/mongod // 备份文件正式目录
DATE=`date +%Y_%m_%d_%H_%M_%S` // 备份文件将以备份对间保存
DB_USER=Guitang // 数库操作员
DB_PASS=qq■■■■■■■■■■■■■■■■■■■■■ // 数掘库操作员密码
DAYS=14 // 保留最新14天的份
TARBAK="mongod_bak_$DATE.tar.gz" // 备份文件命名格式
cd $OUT_DIR // 创建文件夹
rm -rf $OUT_DIR/* // 清空临时目录
mkdir -p $OUT_DIR/$DATE // 创建本次备份文件夹
$DUMP -d wecard -u $DB_USER -p $DB_PASS -o $OUT_DIR/$DATE // 执行备份命令
tar -zcvf $TAR_DIR/$TAR_BAK $OUT_DIR/$DATE // 将份文件打包放入正式
find $TAR_DIR/ -mtime +$DAYS -delete // 除14天前的旧备


And then he ran it and it outputted permission denied messages, so he pressed Ctrl+C. The server shut down automatically. He tried to restart it but got a grub error:



GRUB



He contacted AliCloud, the engineer connected the disk to another working server so that he could check the disk. Looks like some folders are gone, including /data/ where the mongodb is!



  1. We don't understand how the script could destroy the disk including /data/;

  2. And of course, is it possible to get the /data/ back?

PS: He did not take snapshot of the disk before.



PS2: As people mention "backups" a lot, we have lots of important users and data coming these 2 days, the purpose of this action was to backup them (for the first time), then they turned out to be entirely deleted.










share|improve this question



















  • 1





    Your script has no error checking. If the line cd $OUT_DIR fails, it's going to delete everything in the current path, which may well be / . This is why you have backups - use them.

    – Jenny D
    9 hours ago






  • 2





    Possible duplicate of Monday morning mistake: sudo rm -rf --no-preserve-root /

    – Jenny D
    9 hours ago











  • He run the shell under ~/crontab/, how could rm or find -delete delete folders under /?

    – SoftTimur
    9 hours ago












  • Make a raw backup of the full hard disk before yo do anything, this will increase your low changes for data recovery

    – Ferrybig
    5 hours ago






  • 2





    Wow - did this script get into your version control system? Did it go through peer review? rm -rf $OUT_DIR/* really? And why was the script not tested on a non-production server? Once you have restored from backup you have many critical procedural failings to address here before automating anything else. I hope you're not too hard on your developer over it, as a result (though they also have quite a bit to answer for)

    – Lightness Races in Orbit
    2 hours ago
















7















My developer committed a huge mistake and we cannot find our Mongo database anywhere in the server.



He logged into the server, and saved the following shell under ~/crontab/mongod_back.sh:



mongod_back.sh



#!/bin/sh
DUMP=mongodump
OUT_DIR=/data/backup/mongod/tmp // 备份文件临时目录
TAR_DIR=/data/backup/mongod // 备份文件正式目录
DATE=`date +%Y_%m_%d_%H_%M_%S` // 备份文件将以备份对间保存
DB_USER=Guitang // 数库操作员
DB_PASS=qq■■■■■■■■■■■■■■■■■■■■■ // 数掘库操作员密码
DAYS=14 // 保留最新14天的份
TARBAK="mongod_bak_$DATE.tar.gz" // 备份文件命名格式
cd $OUT_DIR // 创建文件夹
rm -rf $OUT_DIR/* // 清空临时目录
mkdir -p $OUT_DIR/$DATE // 创建本次备份文件夹
$DUMP -d wecard -u $DB_USER -p $DB_PASS -o $OUT_DIR/$DATE // 执行备份命令
tar -zcvf $TAR_DIR/$TAR_BAK $OUT_DIR/$DATE // 将份文件打包放入正式
find $TAR_DIR/ -mtime +$DAYS -delete // 除14天前的旧备


And then he ran it and it outputted permission denied messages, so he pressed Ctrl+C. The server shut down automatically. He tried to restart it but got a grub error:



GRUB



He contacted AliCloud, the engineer connected the disk to another working server so that he could check the disk. Looks like some folders are gone, including /data/ where the mongodb is!



  1. We don't understand how the script could destroy the disk including /data/;

  2. And of course, is it possible to get the /data/ back?

PS: He did not take snapshot of the disk before.



PS2: As people mention "backups" a lot, we have lots of important users and data coming these 2 days, the purpose of this action was to backup them (for the first time), then they turned out to be entirely deleted.










share|improve this question



















  • 1





    Your script has no error checking. If the line cd $OUT_DIR fails, it's going to delete everything in the current path, which may well be / . This is why you have backups - use them.

    – Jenny D
    9 hours ago






  • 2





    Possible duplicate of Monday morning mistake: sudo rm -rf --no-preserve-root /

    – Jenny D
    9 hours ago











  • He run the shell under ~/crontab/, how could rm or find -delete delete folders under /?

    – SoftTimur
    9 hours ago












  • Make a raw backup of the full hard disk before yo do anything, this will increase your low changes for data recovery

    – Ferrybig
    5 hours ago






  • 2





    Wow - did this script get into your version control system? Did it go through peer review? rm -rf $OUT_DIR/* really? And why was the script not tested on a non-production server? Once you have restored from backup you have many critical procedural failings to address here before automating anything else. I hope you're not too hard on your developer over it, as a result (though they also have quite a bit to answer for)

    – Lightness Races in Orbit
    2 hours ago














7












7








7


1






My developer committed a huge mistake and we cannot find our Mongo database anywhere in the server.



He logged into the server, and saved the following shell under ~/crontab/mongod_back.sh:



mongod_back.sh



#!/bin/sh
DUMP=mongodump
OUT_DIR=/data/backup/mongod/tmp // 备份文件临时目录
TAR_DIR=/data/backup/mongod // 备份文件正式目录
DATE=`date +%Y_%m_%d_%H_%M_%S` // 备份文件将以备份对间保存
DB_USER=Guitang // 数库操作员
DB_PASS=qq■■■■■■■■■■■■■■■■■■■■■ // 数掘库操作员密码
DAYS=14 // 保留最新14天的份
TARBAK="mongod_bak_$DATE.tar.gz" // 备份文件命名格式
cd $OUT_DIR // 创建文件夹
rm -rf $OUT_DIR/* // 清空临时目录
mkdir -p $OUT_DIR/$DATE // 创建本次备份文件夹
$DUMP -d wecard -u $DB_USER -p $DB_PASS -o $OUT_DIR/$DATE // 执行备份命令
tar -zcvf $TAR_DIR/$TAR_BAK $OUT_DIR/$DATE // 将份文件打包放入正式
find $TAR_DIR/ -mtime +$DAYS -delete // 除14天前的旧备


And then he ran it and it outputted permission denied messages, so he pressed Ctrl+C. The server shut down automatically. He tried to restart it but got a grub error:



GRUB



He contacted AliCloud, the engineer connected the disk to another working server so that he could check the disk. Looks like some folders are gone, including /data/ where the mongodb is!



  1. We don't understand how the script could destroy the disk including /data/;

  2. And of course, is it possible to get the /data/ back?

PS: He did not take snapshot of the disk before.



PS2: As people mention "backups" a lot, we have lots of important users and data coming these 2 days, the purpose of this action was to backup them (for the first time), then they turned out to be entirely deleted.










share|improve this question
















My developer committed a huge mistake and we cannot find our Mongo database anywhere in the server.



He logged into the server, and saved the following shell under ~/crontab/mongod_back.sh:



mongod_back.sh



#!/bin/sh
DUMP=mongodump
OUT_DIR=/data/backup/mongod/tmp // 备份文件临时目录
TAR_DIR=/data/backup/mongod // 备份文件正式目录
DATE=`date +%Y_%m_%d_%H_%M_%S` // 备份文件将以备份对间保存
DB_USER=Guitang // 数库操作员
DB_PASS=qq■■■■■■■■■■■■■■■■■■■■■ // 数掘库操作员密码
DAYS=14 // 保留最新14天的份
TARBAK="mongod_bak_$DATE.tar.gz" // 备份文件命名格式
cd $OUT_DIR // 创建文件夹
rm -rf $OUT_DIR/* // 清空临时目录
mkdir -p $OUT_DIR/$DATE // 创建本次备份文件夹
$DUMP -d wecard -u $DB_USER -p $DB_PASS -o $OUT_DIR/$DATE // 执行备份命令
tar -zcvf $TAR_DIR/$TAR_BAK $OUT_DIR/$DATE // 将份文件打包放入正式
find $TAR_DIR/ -mtime +$DAYS -delete // 除14天前的旧备


And then he ran it and it outputted permission denied messages, so he pressed Ctrl+C. The server shut down automatically. He tried to restart it but got a grub error:



GRUB



He contacted AliCloud, the engineer connected the disk to another working server so that he could check the disk. Looks like some folders are gone, including /data/ where the mongodb is!



  1. We don't understand how the script could destroy the disk including /data/;

  2. And of course, is it possible to get the /data/ back?

PS: He did not take snapshot of the disk before.



PS2: As people mention "backups" a lot, we have lots of important users and data coming these 2 days, the purpose of this action was to backup them (for the first time), then they turned out to be entirely deleted.







filesystems shell ubuntu-14.04 data-recovery disaster-recovery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 56 mins ago







SoftTimur

















asked 9 hours ago









SoftTimurSoftTimur

1137




1137







  • 1





    Your script has no error checking. If the line cd $OUT_DIR fails, it's going to delete everything in the current path, which may well be / . This is why you have backups - use them.

    – Jenny D
    9 hours ago






  • 2





    Possible duplicate of Monday morning mistake: sudo rm -rf --no-preserve-root /

    – Jenny D
    9 hours ago











  • He run the shell under ~/crontab/, how could rm or find -delete delete folders under /?

    – SoftTimur
    9 hours ago












  • Make a raw backup of the full hard disk before yo do anything, this will increase your low changes for data recovery

    – Ferrybig
    5 hours ago






  • 2





    Wow - did this script get into your version control system? Did it go through peer review? rm -rf $OUT_DIR/* really? And why was the script not tested on a non-production server? Once you have restored from backup you have many critical procedural failings to address here before automating anything else. I hope you're not too hard on your developer over it, as a result (though they also have quite a bit to answer for)

    – Lightness Races in Orbit
    2 hours ago













  • 1





    Your script has no error checking. If the line cd $OUT_DIR fails, it's going to delete everything in the current path, which may well be / . This is why you have backups - use them.

    – Jenny D
    9 hours ago






  • 2





    Possible duplicate of Monday morning mistake: sudo rm -rf --no-preserve-root /

    – Jenny D
    9 hours ago











  • He run the shell under ~/crontab/, how could rm or find -delete delete folders under /?

    – SoftTimur
    9 hours ago












  • Make a raw backup of the full hard disk before yo do anything, this will increase your low changes for data recovery

    – Ferrybig
    5 hours ago






  • 2





    Wow - did this script get into your version control system? Did it go through peer review? rm -rf $OUT_DIR/* really? And why was the script not tested on a non-production server? Once you have restored from backup you have many critical procedural failings to address here before automating anything else. I hope you're not too hard on your developer over it, as a result (though they also have quite a bit to answer for)

    – Lightness Races in Orbit
    2 hours ago








1




1





Your script has no error checking. If the line cd $OUT_DIR fails, it's going to delete everything in the current path, which may well be / . This is why you have backups - use them.

– Jenny D
9 hours ago





Your script has no error checking. If the line cd $OUT_DIR fails, it's going to delete everything in the current path, which may well be / . This is why you have backups - use them.

– Jenny D
9 hours ago




2




2





Possible duplicate of Monday morning mistake: sudo rm -rf --no-preserve-root /

– Jenny D
9 hours ago





Possible duplicate of Monday morning mistake: sudo rm -rf --no-preserve-root /

– Jenny D
9 hours ago













He run the shell under ~/crontab/, how could rm or find -delete delete folders under /?

– SoftTimur
9 hours ago






He run the shell under ~/crontab/, how could rm or find -delete delete folders under /?

– SoftTimur
9 hours ago














Make a raw backup of the full hard disk before yo do anything, this will increase your low changes for data recovery

– Ferrybig
5 hours ago





Make a raw backup of the full hard disk before yo do anything, this will increase your low changes for data recovery

– Ferrybig
5 hours ago




2




2





Wow - did this script get into your version control system? Did it go through peer review? rm -rf $OUT_DIR/* really? And why was the script not tested on a non-production server? Once you have restored from backup you have many critical procedural failings to address here before automating anything else. I hope you're not too hard on your developer over it, as a result (though they also have quite a bit to answer for)

– Lightness Races in Orbit
2 hours ago






Wow - did this script get into your version control system? Did it go through peer review? rm -rf $OUT_DIR/* really? And why was the script not tested on a non-production server? Once you have restored from backup you have many critical procedural failings to address here before automating anything else. I hope you're not too hard on your developer over it, as a result (though they also have quite a bit to answer for)

– Lightness Races in Orbit
2 hours ago











3 Answers
3






active

oldest

votes


















21














Easy enough. The // sequence isn't a comment in bash (# is).



The statement OUT_DIR=x // text had no effect*.



Thus what was finally executed was rm -rf /*. The directories that the user couldn't remove gave permission errors, but some directories placed directly underneath / apparently could be removed. You need to restore from backup.




* The peculiar form of bash statement A=b c d e f is roughly similar to:



export A=b
c d e f
unset A


Hence script suceeded to do this:



export OUT_DIR=/data/mongo/tmp
// some text # gives error as `//` isn't an executable file!
unset OUT_DIR





share|improve this answer
































    3














    1) He erroneously assumed that // was a bash comment. It is not, only # is.



    The shell interpreted // text as a normal command, and did not find a binary called //, and did nothing.



    In bash, when you have a variable assignment (OUT_DIR=/data/backup/mongod/tmp) directly preceding a command (// text), it only sets the variable while running the command. Therefore, it unsets OUT_DIR immediately, and when the rm line is reached, OUT_DIR is now unset, and rm -rf / is now called, deleting everything you have permission to delete.



    2) The solution is the same as all rm -rf / cases: restore from backup. There is no other solution because you do not have physical access to the hard drive.






    share|improve this answer








    New contributor




    Ray Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















    • why having physical access to the hard drive may help to restore?

      – SoftTimur
      2 hours ago











    • Possible forensics, professional hard drive recovery methods. I know this because I know that rm -rf is not extremely secure, and doesn't overwrite the hard drive.

      – Ray Wu
      2 hours ago











    • @SoftTimur rm usually just "unlinks" files but the data is still physically there until overwritten. This is why professionals can "undelete" sometimes if they have physical access and you haven't done lots of things with the disk after the catastrophe occurred. If you don't have backups, that's the best you can hope for.

      – Lightness Races in Orbit
      1 hour ago


















    1














    1) Bash comments start with #. Sorry for your loss.
    2) Restore from backup is the only way to proceed here, unfortunately.






    share|improve this answer








    New contributor




    RMPJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.



















      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "2"
      ;
      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: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      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
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f959707%2fdatabase-accidentally-deleted-with-a-bash-script%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      21














      Easy enough. The // sequence isn't a comment in bash (# is).



      The statement OUT_DIR=x // text had no effect*.



      Thus what was finally executed was rm -rf /*. The directories that the user couldn't remove gave permission errors, but some directories placed directly underneath / apparently could be removed. You need to restore from backup.




      * The peculiar form of bash statement A=b c d e f is roughly similar to:



      export A=b
      c d e f
      unset A


      Hence script suceeded to do this:



      export OUT_DIR=/data/mongo/tmp
      // some text # gives error as `//` isn't an executable file!
      unset OUT_DIR





      share|improve this answer





























        21














        Easy enough. The // sequence isn't a comment in bash (# is).



        The statement OUT_DIR=x // text had no effect*.



        Thus what was finally executed was rm -rf /*. The directories that the user couldn't remove gave permission errors, but some directories placed directly underneath / apparently could be removed. You need to restore from backup.




        * The peculiar form of bash statement A=b c d e f is roughly similar to:



        export A=b
        c d e f
        unset A


        Hence script suceeded to do this:



        export OUT_DIR=/data/mongo/tmp
        // some text # gives error as `//` isn't an executable file!
        unset OUT_DIR





        share|improve this answer



























          21












          21








          21







          Easy enough. The // sequence isn't a comment in bash (# is).



          The statement OUT_DIR=x // text had no effect*.



          Thus what was finally executed was rm -rf /*. The directories that the user couldn't remove gave permission errors, but some directories placed directly underneath / apparently could be removed. You need to restore from backup.




          * The peculiar form of bash statement A=b c d e f is roughly similar to:



          export A=b
          c d e f
          unset A


          Hence script suceeded to do this:



          export OUT_DIR=/data/mongo/tmp
          // some text # gives error as `//` isn't an executable file!
          unset OUT_DIR





          share|improve this answer















          Easy enough. The // sequence isn't a comment in bash (# is).



          The statement OUT_DIR=x // text had no effect*.



          Thus what was finally executed was rm -rf /*. The directories that the user couldn't remove gave permission errors, but some directories placed directly underneath / apparently could be removed. You need to restore from backup.




          * The peculiar form of bash statement A=b c d e f is roughly similar to:



          export A=b
          c d e f
          unset A


          Hence script suceeded to do this:



          export OUT_DIR=/data/mongo/tmp
          // some text # gives error as `//` isn't an executable file!
          unset OUT_DIR






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago









          Lightness Races in Orbit

          273416




          273416










          answered 8 hours ago









          kubanczykkubanczyk

          10.4k22745




          10.4k22745























              3














              1) He erroneously assumed that // was a bash comment. It is not, only # is.



              The shell interpreted // text as a normal command, and did not find a binary called //, and did nothing.



              In bash, when you have a variable assignment (OUT_DIR=/data/backup/mongod/tmp) directly preceding a command (// text), it only sets the variable while running the command. Therefore, it unsets OUT_DIR immediately, and when the rm line is reached, OUT_DIR is now unset, and rm -rf / is now called, deleting everything you have permission to delete.



              2) The solution is the same as all rm -rf / cases: restore from backup. There is no other solution because you do not have physical access to the hard drive.






              share|improve this answer








              New contributor




              Ray Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















              • why having physical access to the hard drive may help to restore?

                – SoftTimur
                2 hours ago











              • Possible forensics, professional hard drive recovery methods. I know this because I know that rm -rf is not extremely secure, and doesn't overwrite the hard drive.

                – Ray Wu
                2 hours ago











              • @SoftTimur rm usually just "unlinks" files but the data is still physically there until overwritten. This is why professionals can "undelete" sometimes if they have physical access and you haven't done lots of things with the disk after the catastrophe occurred. If you don't have backups, that's the best you can hope for.

                – Lightness Races in Orbit
                1 hour ago















              3














              1) He erroneously assumed that // was a bash comment. It is not, only # is.



              The shell interpreted // text as a normal command, and did not find a binary called //, and did nothing.



              In bash, when you have a variable assignment (OUT_DIR=/data/backup/mongod/tmp) directly preceding a command (// text), it only sets the variable while running the command. Therefore, it unsets OUT_DIR immediately, and when the rm line is reached, OUT_DIR is now unset, and rm -rf / is now called, deleting everything you have permission to delete.



              2) The solution is the same as all rm -rf / cases: restore from backup. There is no other solution because you do not have physical access to the hard drive.






              share|improve this answer








              New contributor




              Ray Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















              • why having physical access to the hard drive may help to restore?

                – SoftTimur
                2 hours ago











              • Possible forensics, professional hard drive recovery methods. I know this because I know that rm -rf is not extremely secure, and doesn't overwrite the hard drive.

                – Ray Wu
                2 hours ago











              • @SoftTimur rm usually just "unlinks" files but the data is still physically there until overwritten. This is why professionals can "undelete" sometimes if they have physical access and you haven't done lots of things with the disk after the catastrophe occurred. If you don't have backups, that's the best you can hope for.

                – Lightness Races in Orbit
                1 hour ago













              3












              3








              3







              1) He erroneously assumed that // was a bash comment. It is not, only # is.



              The shell interpreted // text as a normal command, and did not find a binary called //, and did nothing.



              In bash, when you have a variable assignment (OUT_DIR=/data/backup/mongod/tmp) directly preceding a command (// text), it only sets the variable while running the command. Therefore, it unsets OUT_DIR immediately, and when the rm line is reached, OUT_DIR is now unset, and rm -rf / is now called, deleting everything you have permission to delete.



              2) The solution is the same as all rm -rf / cases: restore from backup. There is no other solution because you do not have physical access to the hard drive.






              share|improve this answer








              New contributor




              Ray Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.










              1) He erroneously assumed that // was a bash comment. It is not, only # is.



              The shell interpreted // text as a normal command, and did not find a binary called //, and did nothing.



              In bash, when you have a variable assignment (OUT_DIR=/data/backup/mongod/tmp) directly preceding a command (// text), it only sets the variable while running the command. Therefore, it unsets OUT_DIR immediately, and when the rm line is reached, OUT_DIR is now unset, and rm -rf / is now called, deleting everything you have permission to delete.



              2) The solution is the same as all rm -rf / cases: restore from backup. There is no other solution because you do not have physical access to the hard drive.







              share|improve this answer








              New contributor




              Ray Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              share|improve this answer



              share|improve this answer






              New contributor




              Ray Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              answered 2 hours ago









              Ray WuRay Wu

              311




              311




              New contributor




              Ray Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





              New contributor





              Ray Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              Ray Wu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.












              • why having physical access to the hard drive may help to restore?

                – SoftTimur
                2 hours ago











              • Possible forensics, professional hard drive recovery methods. I know this because I know that rm -rf is not extremely secure, and doesn't overwrite the hard drive.

                – Ray Wu
                2 hours ago











              • @SoftTimur rm usually just "unlinks" files but the data is still physically there until overwritten. This is why professionals can "undelete" sometimes if they have physical access and you haven't done lots of things with the disk after the catastrophe occurred. If you don't have backups, that's the best you can hope for.

                – Lightness Races in Orbit
                1 hour ago

















              • why having physical access to the hard drive may help to restore?

                – SoftTimur
                2 hours ago











              • Possible forensics, professional hard drive recovery methods. I know this because I know that rm -rf is not extremely secure, and doesn't overwrite the hard drive.

                – Ray Wu
                2 hours ago











              • @SoftTimur rm usually just "unlinks" files but the data is still physically there until overwritten. This is why professionals can "undelete" sometimes if they have physical access and you haven't done lots of things with the disk after the catastrophe occurred. If you don't have backups, that's the best you can hope for.

                – Lightness Races in Orbit
                1 hour ago
















              why having physical access to the hard drive may help to restore?

              – SoftTimur
              2 hours ago





              why having physical access to the hard drive may help to restore?

              – SoftTimur
              2 hours ago













              Possible forensics, professional hard drive recovery methods. I know this because I know that rm -rf is not extremely secure, and doesn't overwrite the hard drive.

              – Ray Wu
              2 hours ago





              Possible forensics, professional hard drive recovery methods. I know this because I know that rm -rf is not extremely secure, and doesn't overwrite the hard drive.

              – Ray Wu
              2 hours ago













              @SoftTimur rm usually just "unlinks" files but the data is still physically there until overwritten. This is why professionals can "undelete" sometimes if they have physical access and you haven't done lots of things with the disk after the catastrophe occurred. If you don't have backups, that's the best you can hope for.

              – Lightness Races in Orbit
              1 hour ago





              @SoftTimur rm usually just "unlinks" files but the data is still physically there until overwritten. This is why professionals can "undelete" sometimes if they have physical access and you haven't done lots of things with the disk after the catastrophe occurred. If you don't have backups, that's the best you can hope for.

              – Lightness Races in Orbit
              1 hour ago











              1














              1) Bash comments start with #. Sorry for your loss.
              2) Restore from backup is the only way to proceed here, unfortunately.






              share|improve this answer








              New contributor




              RMPJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.
























                1














                1) Bash comments start with #. Sorry for your loss.
                2) Restore from backup is the only way to proceed here, unfortunately.






                share|improve this answer








                New contributor




                RMPJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






















                  1












                  1








                  1







                  1) Bash comments start with #. Sorry for your loss.
                  2) Restore from backup is the only way to proceed here, unfortunately.






                  share|improve this answer








                  New contributor




                  RMPJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  1) Bash comments start with #. Sorry for your loss.
                  2) Restore from backup is the only way to proceed here, unfortunately.







                  share|improve this answer








                  New contributor




                  RMPJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  RMPJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 1 hour ago









                  RMPJRMPJ

                  111




                  111




                  New contributor




                  RMPJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  RMPJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  RMPJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Server Fault!


                      • 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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f959707%2fdatabase-accidentally-deleted-with-a-bash-script%23new-answer', 'question_page');

                      );

                      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







                      Popular posts from this blog

                      Bett Inhaltsverzeichnis Geschichte | Bettformen | Bettgrößen | Andere Bezeichnungen | Bettenmangel | Betten in der bildenden Kunst | Schlafmedizinische Gesichtspunkte | Siehe auch | Literatur | Weblinks | Einzelnachweise | NavigationsmenüBett, Bettstatt, BettstelleCommons: BettBabybetten: Anwendung, Ausstattungsmerkmale und VergleichskriterienWasserbetten. Vorurteile im TestHapfnNursch10.1007/s11818-012-0584-74006250-8AKS4329276-8

                      Luksemburg Sisukord Nimi | Asend | Loodus | Riigikord | Haldusjaotus | Rahvastik | Riigikaitse | Majandus | Taristu | Ajalugu | Eesti ja Luksemburgi suhted | Haridus | Kultuur | Vaata ka | Viited | Välislingid | Navigeerimismenüü50° N, 6° EÜlevaade Luksemburgi kaitsealadest.Luksemburgi rahvaarv. Statistikaamet.World Bank'i andmebaasÜlevaade Luksemburgi loodusest.Ülevaade Luksemburgi metsadest.Guy Colling. "Red List of the Vascular Plants of Luxembourg." Travaux scientifiques du Musée national d’histoire naturelle Luxembourg. 2005.Luxembourg’s biodiversity at risk.Maailma kahepaiksete andmebaas.Denis Lepage. "Luxembourg." Avibase.Ülevaade temperatuuridest. Luksemburgi meteoroloogiateenistus.Ülevaade Luksemburgist. Euroopa Liidu esinduse koduleht.Système politique. TerritoireÜlevaade Luksemburgi rahvastikust. Luksemburgi statistikaamet.Luksemburgi rahvastik. Luksemburgi statistikaamet.The World FactbookMonique Borsenberger, Paul Dickes. "Religions au Luxembourg. Quelle évolution entre 1999-2008". Luksemburgi statistikaamet. 2011.Luksemburgi peapiiskopkond. Catholic-Hierarchy.Luksemburgi armee koduleht.Luksemburgi armee relvastus.Eesti Välisministeerium.Luksemburgi rahvastik. Luksemburgi statistikaamet.Luksemburgi Eesti Seltsi koduleht.Helen Eelrand. "Raadio, mis muutis maailma." Eesti Päevaleht. 13. märts 2004.Ülevaade Luksemburgi haridussüsteemist.Ülevaade Luksemburgi keskkoolidest.Luksemburgr

                      Valle di Casies Indice Geografia fisica | Origini del nome | Storia | Società | Amministrazione | Sport | Note | Bibliografia | Voci correlate | Altri progetti | Collegamenti esterni | Menu di navigazione46°46′N 12°11′E / 46.766667°N 12.183333°E46.766667; 12.183333 (Valle di Casies)46°46′N 12°11′E / 46.766667°N 12.183333°E46.766667; 12.183333 (Valle di Casies)Sito istituzionaleAstat Censimento della popolazione 2011 - Determinazione della consistenza dei tre gruppi linguistici della Provincia Autonoma di Bolzano-Alto Adige - giugno 2012Numeri e fattiValle di CasiesDato IstatTabella dei gradi/giorno dei Comuni italiani raggruppati per Regione e Provincia26 agosto 1993, n. 412Heraldry of the World: GsiesStatistiche I.StatValCasies.comWikimedia CommonsWikimedia CommonsValle di CasiesSito ufficialeValle di CasiesMM14870458910042978-6