drupal

Debian 11 bullseye drupal local environment

Debian 11 bullseye drupal local environment

Clone the repository into ~/projects/drupal/projectname

** Dump database from production **

2. Dump database from prod drupal website using drush:

../vendor/drush/drush/drush sql-dump --gzip --result-file=../db_dump_08072023_1102am_latest.sql

3. Copy dump db from local using rsync

rsync --progress username@domainname.com:~/directory/db_dump_08072023_1102am_latest.tar.gz ~/projects/drupal/projectname

* Create mysql user

Drush export sql-dump gzip

$ drush sql-dump --gzip --result-file=~/path-here/sql-dump.sql

I created my own shell script dump_db.sh to make less hustle.
Inside my dump_db.sh

#!/bin/bash

if [ -z "$1" ];
then
  echo "Please specify if its dev or prod" 
  exit 1
else
  dev="$1"
fi

if [ -z "$2" ];
then 
  echo "Please specify the database name"
  exit 1
else
  db="$2"
fi

echo "Exporting database"
drush sql-dump --gzip --result-file=~/backup/$(date +%Y%m%d-%H.%M)-"$dev"-"$db".sql

I would run this:

$ source dump_db.sh dev drupalista.net

Drupal 7 node creation programmatically

  $node = new stdClass();
  $node->title = "TITLE";
  $node->type = "NODE_TYPE";
  node_object_prepare($node); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
  $node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
  $node->uid = $user->uid; 
  $node->status = 1; //(1 or 0): published or not
  $node->promote = 0; //(1 or 0): promoted to front page
  $node->comment = 1; // 0 = comments disabled, 1 = read only, 2 = read/write

  // Term reference (taxonomy) field

Drush export/import database

Drupal 6 and 7

$ drush cc
$ drush sql-dump > ~/my-sql-dump-file-name.sql

Drupal 8

$ drush cr
$ drush sql-dump > ~/my-sql-dump-file-name.sql

Download Database from the server

$ scp username@example.com:~/my-sql-dump-file-name.sql ~/projects

Import Database

$ drush sql-drop
$ drush sql-cli < ~/my-sql-dump-file-name.sql