Recoverable Security rm and restoring security rm

Source: Internet
Author: User

Recoverable Security rm and restoring security rm

We often use rm to delete some files. If you don't shake your hands, it will be a tragedy. You all know...

After such a tragedy, I decided to never stop it. I overwrote the shell function and executed the secure rm. This function backs up the files to be deleted to the specified directory by date. At the same time, there will be multiple versions based on the deletion time. At the same time, another function is provided to restore the previously deleted files.

# safe rm# Don't remove the file, just move them to a temporary directory.# Files are grouped by remove time.# e.g.#   # pwd => /home/work/#   > rm -r -f aa#   'aa' will move to ~/.TrashHistory/20141018/aa@120111@_home_work_aaRM_BACKUP_PATH=/Users/louzhenlin/.TrashHistoryfunction safe_rm() {    # skip cmd option, e.g. '-rf' in 'rm -rf a b' or '-r/-f' in 'rm -r -f a b'    first_char=${1:0:1}    until [ ! "$first_char" = "-" ]    do        shift        first_char=${1:0:1}    done    # check param    if [ $# -lt 1 ]; then        echo 'usage: rm [-f | -i] [-dPRrvW] file ...'        exit 1    fi    today=`date +"%Y%m%d"`    mvpath=${RM_BACKUP_PATH}/$today    # support for multi version    timestamp=`date +"%H%M%S"`    # create dir if path non-exist    if [ ! -d $mvpath ]; then        mkdir $mvpath    fi    until [ $# -eq 0 ]    do        # fetch absolute path of the file        fpath=$1        fchar=`echo "${fpath:0:1}"`        if [ "$fchar" = "/" ]; then            dist_path="_${fpath}"        else            abs_fpath=`pwd`/$fpath            dist_path="${fpath}@${timestamp}@${abs_fpath}"        fi        # substitue '/' to '_'        final_dist_path=${dist_path//\//_}        # mv to temp trash        mv $fpath $mvpath/$final_dist_path        # next file        shift    done}
The above is the safe_rm function, which is displayed in the backup directory:

➜  ~  ll ~/.TrashHistory/20141021total 32drwxr-xr-x  7 louzhenlin  staff  238 10 21 18:01 .drwxr-xr-x  5 louzhenlin  staff  170 10 21 15:51 ..-rw-r--r--  1 louzhenlin  staff  136 10 20 23:39 a@180117@_Users_louzhenlin_dev_workspace_c_cpp_leveldb_a-rw-r--r--  1 louzhenlin  staff  399 10 14 17:43 aof.log@164609@_Users_louzhenlin_dev_workspace_python_redis_aof_modifer_aof.log-rw-r--r--  1 louzhenlin  staff    0 10 14 11:19 appendonly-1.aof@155727@_Users_louzhenlin_dev_server_redis-2.8.17_appendonly-1.aof-rw-r--r--  1 louzhenlin  staff  399 10 14 17:42 appendonly.aof@155105@_Users_louzhenlin_dev_server_redis-2.8.17_appendonly.aof-rw-r--r--  1 louzhenlin  staff  565 10 21 15:56 appendonly.aof@161315@_Users_louzhenlin_dev_server_redis-2.8.17_appendonly.aof

As you can see, the file contains time and full path information for recovery. The following functions are used for restoration:

# revert files that remove by safe_rm# you can choose the right one in multi files removedfunction revert_rm() {    cd $RM_BACKUP_PATH    # process multi files    until [ $# -eq 0 ]    do        echo "revert for $1:"        for f in `find . -name "$1@*" -print`        do            d=`echo $f | awk -F\/ '{print $2}'`            t=`echo $f | awk -F@ '{print $2}'`            fpath=`echo $f | awk -F@ '{print $3}'`            fpath=${fpath//_/\/}            echo -n "      $fpath at ${d:0:4}-${d:4:2}-${d:6:2} ${t:0:2}:${t:2:2}:${t:4:2}   [y/n]? "            read confirm            if [ "${confirm}" = 'y' ]; then                mv $f $fpath                break            fi        done        shift    done}
Revert_rm will list multiple versions of files to be restored.

➜  ~  revert_rm appendonly.aofrevert for appendonly.aof:      /Users/louzhenlin/dev/server/redis-2.8.17/appendonly.aof at 2014-10-21 15:51:05   [y/n]? n      /Users/louzhenlin/dev/server/redis-2.8.17/appendonly.aof at 2014-10-21 16:13:15   [y/n]? y
You can create an alias command to direct rm to safe_rm. Hope everyone can have a good time.






Can the RM file be recovered if it is accidentally deleted?

After you accidentally delete a file, you still have the opportunity to restore the deleted file as long as you have not written the file to the partition of the deleted file. However, we cannot guarantee that all data is restored. Currently, there are many data recovery software, such as EasyRecovery Pro and finaldata‑ise20. Here I recommend EasyRecovery Pro. At the same time, I will introduce the data recovery steps in WINDOWS and DOS scenarios. Hope to help you.

During daily use of the computer, everyone may have trouble deleting data by mistake, formatting hard disk partitions by mistake, or even deleting hard disk partitions by mistake. So how can we restore the deleted data after these situations?
Recover data in Windows
If you have deleted some files by mistake, such as Word files and text files, or mistakenly formatted non-system partitions while Windows is still running normally, you can use EasyRecovery Pro to restore data.
Tip: when installing the software, Note: If you need to retrieve the files accidentally deleted on drive C, you 'd better not install EasyRecovery Pro on drive C. Otherwise, the file system on drive C will be affected, which is detrimental to data recovery.
1. Restore deleted objects by mistake
After EasyRecovery Pro 6.0 is started, click the "Data Recovery" button on the left of the main interface, and then click the "Deleted Recovery" button in the window on the right.
After a short scan, the program requires the user to select the partition where the File is accidentally deleted, and then enter the File name and type of the File to be restored in the "File Filter" column on the right. By default, the program searches for all deleted files. This allows you to find all deleted files. Generally, you can use the default value. Note: If the file has been deleted for a long time, we recommend that you select the check box before "Complete Scan", so that the chances of successful recovery are higher.
Click "Next", the program starts to scan the partition, and a file list window pops up. This window is similar to "Resource Manager". You only need to find the file to be restored in the list and add "√.
Tip: After the deleted files are found by EasyRecovery Pro, the file names in the file list may be different from the original file names. Therefore, be patient when searching for the files to be restored, you can determine whether to restore the file based on the file name and file type. In addition, after selecting a File, you can click the "View File" button to View the content of the selected File, which is very useful for searching text files.
After selecting the file to be restored, click "Next". The program requires you to select a directory to store the recovered file. Note: To ensure recovery security, it is recommended that you store the recovered data in other partitions (for example, if the file to be recovered is on disk D, you can save the files to disk E ). Click "Browse" next to "Recover to Local Drive" and select the target directory in the pop-up window.
Tip: After the deleted files are found by EasyRecovery Pro, the file names in the file list may be different from the original file names. Therefore, be patient when searching for the files to be restored, you can determine whether to restore the file based on the file name and file type. In addition, after selecting a File, you can click the "View File" button to View the content of the selected File, which is very useful for searching text files.
After selecting a directory for storing recovery files, click "Next" and the program will restore the selected files to the set folder.
2. Restore incorrectly formatted partition data
After starting the program, click "Data Recovery" and then click "Format Recovery" in the right window. At this time, the program requires the user to select the partition for Data Recovery.
Tip: if you have not only formatted the partition, but also changed the partition format (for example, from NTFS to FAT32), You must select "Previous File S ...... remaining full text>

Can deleted rm files be recovered?

Scan the hard disk with EasyRecovery software to list the files that can be recovered, and then select another disk to restore and save it. Of course, if you delete a file on drive D and add a file to drive D, you may not be able to recover it because the newly added file may overwrite the location of the previously deleted file.
Original software: nj.onlinedown.net/soft/11308.htm
Localized Patch: nj.onlinedown.net/soft/35758.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.