SSH Commands to find files on Linux Server
If you have a dedicated server or a VPS - or any Linux machine with SSH access, the following commands may be useful to you if you are looking to find some files quickly. PuTTY is a good telnet/SSH client if you don't already have one. Let's get started.
#1: If you are looking for a particular file in /home directory
find /home -name filename
#2: If you are looking for files whose name is starting with "filename" in public_html directories only, you can use the following command:-
find /home/*/public_html -name filename*
#3: Instead of viewing your search results in command line, you can write it to file by using this:
find /home/*/public_html -name filename* > /home/filename_search.txt
#4: Alternatively, you can send it via e-mail directly from server using the command below. Don't forget to replace "Subject Here" with your email subject, and "email.address@domain" with your email ID.
find /home/*/public_html -name filename* |mail -s "Subject Here" e-mail.address@domain
I hope this was useful.
Data recovery from a corrupt hard disk
Earlier this week, I was transferring all my important data from my external 120GB USB hard disk to my new laptop. During the process, the transfer became unbearably slow. I decided to cancel it and reboot my computer to get a fresh start.
To my dismay, Windows Vista detects the hard drive but is unable to read it prompting me to format the drive. After a bit of reading, and trying to access the drive in different ways - I got the following error message.
Disk is unaccessible.
The file or directory is corrupted and unreadable.
It was impossible for me to let go of all my data and thus, I started looking into ways to recover it.
During the process, I realized that the format of my drive had changed from NTFS to RAW - which was rather strange. Searching through Google on Data Recovery Software, I stumbled upon a neat software called R-Studio. I downloaded its trial version to give it a try.
It took approximately 7 hours for it to scan through my corrupt hard drive - after which I could view all my folder structure & files in the hard drive. You can only preview data or recover upto 64 Kb in the demo version of R-Studio. I tested its recover data tool and was very impressed to see that it managed to recover my data.
I purchased the full version of the software for a worthy price of USD 79.99 - got the license key immediately after making payment and started off recovering my data.
Thanks to R-Studio, I have recovered most of my data - besides some that resided on bad clusters.
How do I restore a MySQL dump?
If you have an all-database MySQL dump, follow the instructions below to restore your SQL file with all database data & privileges.
Please note that the following procedures require command line access and is assuming you are the administrator of the computer.
Step 1:
Open up command line.
Start > Run > Type 'cmd' > Enter
Step 2:
Change directory to your MySQL bin folder. This can be C:\Program Files\MySQL\MySQL 4.1 Server\bin -- or C:\xampp\mysql\bin depending on what your setup is like. You can do so by the 'cd' command as follows:
cd C:\xampp\mysql\bin
Step 3:
Ensure that you have moved your backup file (eg: db_backup.sql) into the bin folder and run the following command where test is an empty MySQL database.
mysql -u root -p test < db_backup.sql
It will prompt you for your root password. Enter that and it will start importing your SQL file. It can take several minutes depending on how big your SQL file is.
Good luck!
How to backup MySQL server?
Recently, I bought a new laptop and was challenged to move my development sites over. Copying files and sites is all pretty easy, however, if you do not backup your MySQL server correctly - you will face quite a hassle recreating all the databases and privileges.
I came across the following way that was pretty easy to move around 150 databases with their privileges swiftly.
Please note that the following procedures require command line access and is assuming you are the administrator of the computer.
Step 1:
Open up command line.
Start > Run > Type 'cmd' > Enter
Step 2:
Change directory to your MySQL bin folder. This can be C:\Program Files\MySQL\MySQL 4.1 Server\bin -- or C:\xampp\mysql\bin depending on what your setup is like. You can do so by the 'cd' command as follows:
cd C:\xampp\mysql\bin
Step 3:
Type in the following command to dump all databases into an sql file.
mysqldump --all-databases > db_backup.sql
This can take several minutes depending on the size of your databases. Once done, check your bin folder for db_backup.sql file which contains SQL queries of your entire MySQL server.
You may want to see my other post regarding restoring MySQL server.
