Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

Friday, October 25, 2013

Drupal backup and restore using Drush

 

Drush is a very poweful command line tool to manage Drupal efficiently.

You can manage your drupal site very well using this tool. 

Starting from Drupal installation, you can 

1) Download themes and modules
2) Enable themes and modules
3) Disable themes and modules
4) uninstall modules
5) Clearing cache
6) Backup root files & database
7) Restore them to new site

Some useful drush commands :

Before running the command, first go to desired directory.

Ex: If you want to enable commerce module, first go to /var/www/docroot/sites/all/modules/contrib
drush dl commerce  - will download the commerce module.
drush en commerce - will enable it
drush uninstall commerce - will uninstall it
drush dis commerce - will disable it&nbsp
drush cc all - will clear all cache&nbsp

Backup and restore :

Backup:

As i said before go to your root directory before running below command.
drush archive-dump --destination=/var/back_up/yoursite_today.com.tar.gz

( or )

drush ard --destination=/var/back_up/yoursite_today.com.tar.gz



 Restore :

drush archive-restore /var/back_up/yoursite_today.com.tar.gz --destination=/var/www/new_site.com

( or )

drush arr /var/back_up/yoursite_today.com.tar.gz --destination=/var/www/new_site.com

When you go to your backup directory, there will be one MANIFEST.ini which will contain backup details as in below.

[Global]
datestamp = "1382704323"
formatversion = "1.0"
generator = "Drush archive-dump"
generatorversion = "6.0-beta1"
archiveformat = "platform"

[default]
docroot = "/var/www/beta_bbd"
sitedir = "sites/default"
files-public = "sites/default/files"
database-default-file = "beta_bbd.sql"
database-default-driver = "mysql"
 
Click here to see more about Drush . Another useful link.


Tuesday, May 14, 2013

MySQL Database Back up and Restore (Back up From the Command Line)

If you have shell or telnet access to your web server, you can backup your MySQL data by using the mysqldump command. This command connects to the MySQL server and creates an SQL dump file. The dump file contains the SQL statements necessary to re-create the database.

Here is the proper syntax:
$ mysqldump -u [uname] -p[pass] [dbname] > [backupfile.sql]
Code for compressed format:
$ mysqldump -u [uname] -p[pass] [dbname] | gzip > [backupfile.sql.gz] 
If your db server located in remote system, using its IP & port we can take the back up :
$ mysqldump -P 3301 -h 231.200.12.45 -u [uname] -p[pass] [dbname] | gzip > [backupfile.sql.gz] 
Compressed format to store more space. Compare to .sql format, .sql.gz size is very very less. To see it in action, use below command to see the size of both files :
 ll -sh
Take back up of root files :
 tar -pczf filename.tar.gz /your/file/path
To extract this file, use below command :
 tar -zxvf filename.tar.gz 
Import  back sql file. Directly you can import file.sql.gz file into your database. 
use below command to do it.
 gunzip < file.sql.gz | mysql -u [uname] -p[pass] [dbname] 
For more details refer this link.