Installation


Upgrades


DTC-Xen Installation


DTC-Xen / Dom0 Howtos

DTC-Xen / DomU Howtos

FAQ


DTC Howtos


Manuals


Features


Roadmap


Devel docs


Wiki - i18n


Wiki - Meta


Restore-Files-Script-For-Dirvish

First we need to connect from our production server to our backup, so we uses SSH rsa keys.

Setting-up ssh keys

Same as we did when setting up dirvish, we do it the other way around.

As root user on the production server, create a pair of private and public ssh keys:

   prod# ssh-keygen -t rsa

When ask for the path, just type enter. When asked for a passphrase, enter an empty passphrase (just type enter), because nobody will be on the keyboard to type it. Do not worry, this is still very safe. Next, you have to copy the public key of the backup server into the production server. Just read the public key on the backup server with:

   prod# cat /root/.ssh/id_rsa.pub

Set the ssh files and user into the Production server. Something like this:

   back# mkdir /root/.ssh
   back# chown root:root /root/.ssh
   back# chmod 700 /home/dirvish/.ssh
   back# echo "ssh-rsa <your-ssh-key>" >/root/.ssh/authorized_keys
   back# chown root:root /home/dirvish/.ssh/authorized_keys
   back# chmod 600 /home/dirvish/.ssh/authorized_keys

Copy the content of the ssh public key (see above) and paste it into your newly created file "authorized_keys" Note that copying the email address at the end of the key is often a bad idea, because if the rDNS of the backup is wrong, your production server will not let you in. Next, simply try, from the backup server and being root, to login as the dirvish user in your production server:

   prod# ssh root@backup.example.com

After we can connect with ssh, we copy this restore script to a new file:

Create new file:

   prod# pico /root/restore.sh

Copy and paste the restore script:

#!/bin/bash

BACKUP_DIR="/var/backup/dtc.CHANGEME.com"

# Change BACKUP_DIR and remove the two lines below
echo "change BACKUP_DIR!!!"
exit 1


SERVER_DIR="/var/www/sites"

for i in "$@"
do
case $i in
    restore*)
    RESTORE='1'
    ;;

    list*)
    LIST='1'
    ;;

    -u=*|--user=*)
    DTC_USER="${i#*=}"
    ;;

    -dtr=*|--datetorestore=*)
    DATE_TO_RESTORE="${i#*=}"
    ;;

    -d=*|--domain=*)
    DOMAIN="${i#*=}"
    ;;

    -s=*|--subdomain=*)
    SUBDOMAIN="${i#*=}"
    ;;
    -h|--help)
        echo " "
        echo "      Usage: restore.sh list : lists current backup dates"
        echo "             restore.sh restore -dtr=<date to restore> -u=<user> -t=<domain> -s=<subdomain> : restore an account"
        echo " "
        echo "   -dtr, --datetorestore=<date>          Date to restore. get the dates with ./restore.sh list"
        echo "   -u,   --user=<user>                   DTC admin username"
        echo "   -d,   --domain=<domain.com>           Domain name to restore. i.e example.com"
        echo "   -s,   --subdomain=<subdomain>         Subdomain to restore. i.e. www"
        echo " "
        echo "   -h,   --help                          Display this help and exit"
        echo " "
        exit 1

    ;;
esac
done

if [[ ${LIST} ]]; then

rsync -t --list-only --exclude="dirvish" root@linux-hosting.pw:$BACKUP_DIR/ | awk '{ print $NF }'

exit 1

fi

    if [ -z ${DTC_USER} ] || [ -z ${DATE_TO_RESTORE} ] || [ -z ${DOMAIN} ] || [ -z ${SUBDOMAIN} ]; then

        echo 'Missing:'
        if [[ -z ${DTC_USER} ]]; then 
        echo '-u=<DTC USER>'
        fi

        if [[ -z ${DATE_TO_RESTORE} ]]; then 
        echo '-dtr=<DATE TO RESTORE>'
        fi

        if [[ -z ${DOMAIN} ]]; then 
        echo '-d <DOMAIN>'
        fi

        if [[ -z ${SUBDOMAIN} ]]; then 
        echo '-s <SUBDOMAIN>'
        fi
        echo "type: restore.sh --help or -h for help"
        exit 1
    fi

if [[ -n ${RESTORE} && -n ${DTC_USER} && -n ${DATE_TO_RESTORE} && -n ${DOMAIN} && -n ${SUBDOMAIN} ]]; then

echo RESTORE = ${RESTORE}
echo DTC_USER = ${DTC_USER}
echo DATE_TO_RESTORE = ${DATE_TO_RESTORE}
echo DOMAIN = ${DOMAIN}
echo SUBDOMAIN = ${SUBDOMAIN}

echo "Removing old directory..."
rm -rf $SERVER_DIR/${DTC_USER}/${DOMAIN}/subdomains/${SUBDOMAIN}/html/.??*
rm -rf $SERVER_DIR/${DTC_USER}/${DOMAIN}/subdomains/${SUBDOMAIN}/html/*

echo "Restoring..."
rsync -rlptDvz --owner=dtc --group=dtcgrp root@linux-hosting.pw:$BACKUP_DIR/${DATE_TO_RESTORE}/tree/sites/${DTC_USER}/${DOMAIN}/subdomains/${SUBDOMAIN}/html/ $SERVER_DIR/${DTC_USER}/${DOMAIN}/subdomains/${SUBDOMAIN}/html/

exit 1
fi

REMEMBER! change BACKUP_DIR to the backup directory of your server. Save the file (Ctrl + X) and change mode:

   prod# chmod 700 /root/restore.sh

After all done run:

   prod# cd /root/
   prod# ./restore

   Usage: restore.sh list : lists current backup dates
          restore.sh restore -dtr=<date to restore> -u=<user> -t=<domain> -s=<subdomain> : restore an account

Hope that helps anyone.

Editing this page means accepting its license.

Page last modified on September 27, 2014, at 12:43 AM EST