Need a linux command line guru... HELP please.

csgo

Verified User
Joined
Feb 29, 2012
Messages
47
I had a serious bad chain of events and ended up losing user data. I send the backup drive to a recovery service and they have successfully recovered all the Admin backups, but they are not in the correct file name format.

For example, DirectAdmin saves the backup file name as user.reseller.username.tar.gz (using the actual reseller and username of course). The reseller name is not important since they're all the same, but I need to recover the username and rename the files properly.

The data recovery service is returning the files to me as randomstuff.gz From the sample they sent me it looks like all the data is there, but I can't restore a file named "Pdijrldsjw.gz". I need to extract the username and rename the file in the user.reseller.username.tar.gz format.

It would be a great help if some of you linux wizards could give me a small script that will extract the username from the randomstuff.gz and then rename the file in the user.reseller.username.tar.gz DirectAdmin format.

I might not live long enough to do it manually.

Thank you very much in advance!

-Joe
 
Hello Joe,

It will something similar to this:

Code:
#!/bin/bash

for f in `ls -1 *.gz`;
do
    creator="";
    username="";
    usertype="";
    echo "Found $f";
    usercnf="backup/user.conf";
    tar -zxvf $f $usercnf;
    if [ -f "$usercnf" ];
    then
        creator=`grep ^creator= $usercnf | cut -d\= -f2`;
        username=`grep ^username= $usercnf | cut -d\= -f2`;
        usertype=`grep ^usertype= $usercnf | cut -d\= -f2`;
        echo "Creator=$creator username=$username and usertype=$usertype";
        mv -fv $f $usertype.$creator.$username.tar.gz;
        rm -f $usercnf;
    fi;
done;

save it to recover_filenames.sh with

Code:
chmod 755 recover_filenames.sh

and run it in the directory with recovered files. You will output similar to this:

Code:
Found ufwfsdftr.gz
backup/user.conf
Creator=admin username=bob and usertype=user
`ufwfsdftr.gz' -> `user.admin.bob.tar.gz'
 
Alex,

Thank you. Fortunately I got a guy at the datacenter to do just that. He will also do it on the rest of the domains I'll re-load tomorrow.

I've hired you for other work and really appreciate your help!

Thanks,
-Joe
 
Back
Top