Results 1 to 6 of 6

Thread: How do I restore deleted files from rsync?

  1. #1
    Join Date
    Jan 2010
    Beans
    18

    How do I restore deleted files from rsync?

    I used the following command


    rsync -avh --progress --remove-source-files --delete /mnt/disk-1/* /mnt/disk-2
    I thought that `delete` would overwrite files in my destination directory. But instead, it deleted the files in the destination directory if they didn't exist in the source directory.


    I tried restoring files with `ext4magic`, `extundelete`, `testdisk` and had no luck.


    `ext4magic`, tries to restore the files but I get `segmentation fault` and stops...


    Both filesystems are `ext4`


    Any programs I could try?
    Last edited by MariosFFX; 3 Weeks Ago at 02:44 PM.

  2. #2
    Join Date
    Jun 2014
    Beans
    7,407

    Re: How do I restore deleted files from rsync?

    it deleted the files in the destination directory if they didn't exist.
    I believe a better explanation of what you intended and what happened is required. Read that statement and think about the logic. It is not possible to delete files that do not exist!

  3. #3
    Join Date
    Jan 2010
    Beans
    18

    Re: How do I restore deleted files from rsync?

    Quote Originally Posted by yancek View Post
    I believe a better explanation of what you intended and what happened is required. Read that statement and think about the logic. It is not possible to delete files that do not exist!
    Corrected. It somehow tried to sync the files. If the file wasn't on the source directory then it would delete it in the destination directory, for example

    Source:
    source/dir-1/

    Destination
    destination/dir-1/a.md
    destination/dir-1/b.md
    destination/dir-1/c.md

    The files in the destination didn't exist, so rsync deleted them.


    What I tried to do was to merge the contents of directories, I wanted for example:

    Source 1:
    source-1/dir-1/a.md
    source-1/dir-1/b.md
    source-2/dir-1/c.md

    Source 2:
    source-2/dir-1/c.md
    source-2/dir-1/d.md


    I wanted the following result
    destination/dir-1/a.md
    destination/dir-1/b.md
    destination/dir-1/c.md
    destination/dir-1/d.md

    And I ended up with empty directories. The above command deleted the files from the destination as well as from the source.
    Last edited by MariosFFX; 3 Weeks Ago at 02:51 PM.

  4. #4
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: How do I restore deleted files from rsync?

    Quote Originally Posted by MariosFFX View Post
    And I ended up with empty directories. The above command deleted the files from the destination as well as from the source.
    To accomplish that, I would have used rm instead. Much clearer.

    If you want to restore files, use the backup you made before doing anything risky.

    Linux (and rsync) follows the UNIX philosophy, which simply asks, "can I do what was asked?" The program doesn't know if what is being asked is brilliant or stupid, just whether it can take the inputs, honor the options, and create the outputs from those options and inputs. Seems to me, it did what you asked.

    You do know about the --dry-run option for rsync, right?
    Some key things in the rsync manpage:
    Code:
           --remove-source-files    sender removes synchronized files (non-dir)
           --delete                 delete extraneous files from dest dirs
           --delete-before          receiver deletes before xfer, not during
           --delete-during          receiver deletes during the transfer
           --delete-delay           find deletions during, delete after
           --delete-after           receiver deletes after transfer, not during
           --delete-excluded        also delete excluded files from dest dirs
           --dry-run, -n            perform a trial run with no changes made
    So it appears that then each option is checked matters.

    Also, when doing destructive things, it is important to read all the caveats in the manpage to ensure there aren't any unintended consequences.

    If you just want to move files, across file systems, I'd use the 'mv' command, not rsync. There are a number of ways to locally mount remote storage, if it isn't on the same computer. sshfs would be the worst case, though I wouldn't expect symbolic links to be correct after the move.

  5. #5
    Join Date
    Apr 2024
    Beans
    41

    Re: How do I restore deleted files from rsync?

    You have two file systems essentially without being aware of the fact, like most people. There is the file system that you are aware of, then there is the file system that you are not aware of, that your storage device uses to arrange data. When you deleted files, in the context of the file system you are aware of, you deleted files, in the context of the file system you are aware of.

    The question you're asking is the big money question, that does not have great answers actually.

  6. #6
    Join Date
    Mar 2011
    Location
    U.K.
    Beans
    Hidden!
    Distro
    Ubuntu 22.04 Jammy Jellyfish

    Re: How do I restore deleted files from rsync?

    I suggest you use in future grsync (the rsync GUI) and enable "dry run".
    And fall back on backups .. in case of disaster.

    Why do some discussions remind me of Danny Kaye in the Court Jester?


    • Griselda : Listen. I have put a pellet of poison in one of the vessels.
      Hawkins : Which one?
      Griselda : The one with the figure of a pestle.
      Hawkins : The vessel with the pestle?
      Griselda : Yes. But you don't want the vessel with the pestle, you want the chalice from the palace!
      Hawkins : I don't want the vessel with the pestle, I want the chalice from... the what?
      Jean : The chalice from the palace!
      Hawkins : Hmmm?
      Griselda : It's a little crystal chalice with a figure of a palace.
      Hawkins : The chalice from the palace has the pellet with the poison?
      Griselda : No, the pellet with the poison's in the vessel with the pestle.
      Hawkins : Oh, oh, the pestle with the vessel.
      Jean : The vessel with the pestle.
      Hawkins : What about the palace from the chalice?
      Griselda : Not the palace from the chalice! The chalice from the palace!
      Hawkins : Where's the pellet with the poison?
      Griselda : In the vessel with the pestle.
      Griselda : The chalice from the palace has the brew that is true.
      Jean : Don't you see? The pellet with the poison's in the vessel with the pestle.
      Griselda : The chalice from the palace has the brew that is true!
      Jean : It's so easy, I can say it.
      Hawkins : Well then you fight him!
      Griselda : Listen carefully. The pellet with the poison's in the vessel with the pestle, the chalice from the palace has the brew that is true.
      Hawkins : The pellet with the poison's in the vessel with the pestle, the chalice from the palace has the brew that is true.
      Jean : Good man!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •