Archive for : May, 2015

Mysqldump only tables with certain prefix

Mysqldump only tables with certain prefix:


mysqldump DBNAME $(mysql -D DBNAME -Bse "show tables like 'wp_%'") > FILENAME.sql

SSL Certificates with Apache 2 on CentOS

Generate a Self-Signed Certificate

At the shell prompt, issue the following commands to install SSL for Apache and generate a certificate:


yum install mod_ssl
mkdir /etc/httpd/ssl
openssl req -new -x509 -sha256 -days 365 -nodes -out /etc/httpd/ssl/httpd.pem -keyout /etc/httpd/ssl/httpd.key

Configure Apache to use the Self-Signed Certificate


NameVirtualHost *:443

SSLEngine On
SSLCertificateFile /etc/httpd/ssl/httpd.pem
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
ServerAdmin info@mydomain.com
ServerName www.mydomain.com
DocumentRoot /srv/www/mydomain.com/public_html/
ErrorLog /srv/www/mydomain.com/logs/error.log
CustomLog /srv/www/mydomain.com/logs/access.log combined

Restart Apache:


service httpd restart

Tar and untar files and folders

tar

tar files


tar cvf dest.tar file.txt file2.txt

Tarring folders

tar cvf dest.tar myfolder/

Untar the file or folder


tar xvf dest.tar

tar.gz

Compress using gzip:


tar cvfz dest.tar.gz myfolder/

Uncompress zip file:


tar xvfz dest.tar.gz

tar.bz


tar cvjf dest.tar.bz2 myfolder/

Extract:


tar xvjf dest.tar.bz2

Extracting individual files


tar xvjf dest.tar.bz2 textfile.txt

Ubuntu – Executing a script at startup and shutdown

To execute a script at startup of Ubuntu

  • Edit /etc/rc.local and add your commands
  • The script must always end with exit 0

To execute a script upon rebooting Ubuntu:

  • Put your script in /etc/rc0.d
  • Make it executable (sudo chmod +x myscript)
  • Note: The scripts in this directory are executed in alphabetical order

The name of your script must begin with K99 to run at the right time.

To execute a script at shutdown:

  • Put your script in /etc/rc6.d
  • Make it executable (sudo chmod +x myscript)
  • Note: The scripts in this directory are executed in alphabetical order

The name of your script must begin with K99 to run at the right time.

Watch the entire article here

Exporting and Importing Compressed MySQL Databases

This command will dump a MySQL database, compress it and save it to a file (replace userName and databaseName with your data):


mysqldump -u userName -p databaseName | gzip > databaseName.sql.gz

The import command takes a compressed MySQL dump, decompresses it and adds it to the database (replace userName and databaseName with your data):


gzip -dc < databaseName.sql.gz | mysql -u userName -p databaseName