SSH Commands

  • Post category:SSH
  • Post comments:0 Comments

Login to SSH using terminal

ssh [email protected] -p22456

Extract a tar.bz2 file

tar jxf file.tar.bz2

Backing up Database: The command for backing up your database is the following:

mysqldump -u username -p database_name -hServerIP > /path/backup.sql

Type the above command in your command line with your username, database_name, and storage_path for dump to be saved in, press Enter and you will be prompted for your database user’s password.

Restoring your Database: The command for restoring your database is the following:

mysql -u username -pPassword -hServerIP database_name < path/db.sql

Note the lack of a space between -p and Password. Also, the password is for the MySQL database.

<strong>Compressed dumps/restores</strong>: In order to restore a compressed database, you will have to uncompress the file first. The following command combines both the steps of uncompressing your file and transferring its contents to a database:

gunzip < backup.sql.gz | mysql -u blarg -pPassword db_name

If you want to directly compress data from a mySQL database without having to gzip separately, enter the following command:

mysqldump -u username -p -hServerIP db_name | gzip > backup.sql.gz

After you type the above and press enter, you should be prompted for your password. Enter your password, and you should be all set.

Compress/Uncompress: If you want to compress your existing .sql file, you will need to use the following command:

gzip -X path/to/backup.sql

In the above command, X is a number between 1 and 9 that specifies the level of compression used. The higher your number, the more compressed (smaller) your file will be.

For example, this is the command I use to compress my data:

gzip -9 forum_backup.sql

Likewise, to uncompress a compressed file, you will use the following command:

gunzip backup.sql.gz