MySQL: Backup Database with mysqldump from the Command Line

Backups are an essential part of development. You always want backups. mysqldump is the goto program to backup mysql databases

Backup a database

mysqldump database_name > database_dump.sql

Backup a database with username and password

mysqldump -u username -p password database_name > database_dump.sql

Backup a database with username and password and compressed

Gzip
mysqldump -u username -p password database_name | gzip > database_dump.sql.gz
Bzip
mysqldump -u username -p password database_name | bzip2 > database_dump.sql.bz2

 Nginx Essential Commands

NGINX is a free, open-source, high-performance HTTP server. NGINX usage has been growing in the past few years and you should at least learn some commands that you could use with NGINX.

First, Install NGINX

Debian/Ubuntu

apt-get install nginx

CentOS/RHEL

yum install nginx

Now, let’s get to the essential commands

Check NGINX status

$ service nginx status
$ service nginx status
nginx found running with processes:  15423 15422 15421 15420 15418 15417 15416 15414 15412

Stop NGINX

$ service nginx stop
$ service nginx stop
 * Stopping Nginx Server...                                                                                                                            [ OK ]

Start NGINX

$ service nginx start
$ service nginx start
 * Starting Nginx Server...                                                                                                                            [ OK ] 

Restart NGINX

This will do the above commands, stop and start

$ service nginx start
$ service nginx restart
 * Stopping Nginx Server...                                                                                                                            [ OK ] 
 * Starting Nginx Server...                                                                                                                            [ OK ] 

Reload NGINX Configuration

$ service nginx reload
$ service nginx reload
nginx: the configuration file /etc/conf/nginx.conf syntax is ok
nginx: configuration file /etc/conf/nginx.conf test is successful
 * Reloading (via HUP) Nginx Server...                                                                                                                        
Hangup

Come on and try these commands out on environment!

 How to Compress a Folder using Tar

How do you compress a folder using the Tar Command?

Every time I need to compress a file, I google the answer. I am quite tired of that and decided to write myself mine. Here’s a good tutorial about compressing files using the Tar Command.

1 Go to the location of the folder

$ cd /location

2 Use the tar command to compress the file

The important aspect of the command below is the -c which translates to compress

$ tar -zcvf a folder.tar.gz system
system/
system/popups/
system/popups/photos/
system/popups/photos/000/
system/popups/photos/000/000/
system/popups/photos/000/000/001/
system/popups/photos/000/000/001/photo_thumb/
system/popups/photos/000/000/001/photo_thumb/Free-Phyto.jpg
system/popups/photos/000/000/001/photo_main/
system/popups/photos/000/000/001/photo_main/Free-Phyto.jpg
system/popups/photos/000/000/001/original/
system/popups/photos/000/000/001/original/Free-Phyto.jpg

Voila! A compressed file!

$ ls
-rw-rw-r--  1 group group 190M Nov  4 13:25 folder.tar.gz

How to Extract a Tar Compressed File

In the last tutorial, we compressed a folder using the Tar command. Here’s another for extracting from a tar compressed file.

1 Go to the location of the Tar compressed file

cd /location

2 Use the Tar command

The important aspect of the command below is the -x which translates to extract

$ tar -zxvf folder.tar.gz 
system/
system/popups/
system/popups/photos/
system/popups/photos/000/
system/popups/photos/000/000/
system/popups/photos/000/000/001/
system/popups/photos/000/000/001/photo_thumb/
system/popups/photos/000/000/001/photo_thumb/Free-Phyto.jpg
system/popups/photos/000/000/001/photo_main/
system/popups/photos/000/000/001/photo_main/Free-Phyto.jpg
system/popups/photos/000/000/001/original/
system/popups/photos/000/000/001/original/Free-Phyto.jpg
ls -lah
drwxrwxr-x  9 group group 4.0K Nov  4 10:12 system

Bookmark this Tutorial for reading. Thanks!

 How to Extract or Uncompress a CPGZ file on a Mac

As someone who handles a lot of files from time to time. I seem to have been getting problems when I encounter files with the extension, cpgz

Whenever, I extract from it, I get a zip file and extracting the zip file creates another cpgz file.

Here is an easy way to extract a cpgz file on a Mac.

First, you need to install 7zip:

brew install p7zip

Second, extract away.

7za x /Users/thorpeobazee/Downloads/myfile.cpgz
7-Zip (A) [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=utf8,Utf16=on,HugeFiles=on,4 CPUs)

Processing archive: /Users/thorpeobazee/Downloads/myfile.zip.cpgz

Extracting  myfile.zip

Everything is Ok

Size:       69632
Compressed: 69226

You will need to unzip the uncompressed file.

Processing archive: /Users/thorpeobazee/Downloads/myfile2.zip

Extracting  myfile2.txt

Everything is Ok

Size:       186382
Compressed: 69632

Good luck extracting!