aboutsummaryrefslogtreecommitdiff
path: root/share/hydractl/backup-restore-site
blob: 2ca7655bb4ad824de55ec0e3d885a431780ab6a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#
# Restore a website from backup
#
# TODO: moin, ikiwiki, etc

# Load.
source $APP_BASE/lib/hydra/functions || exit 1
hydra_config_load

SITE="$2"
SITES="/var/sites"
FOLDER="$SITES/$SITE"

if [ -z "$SITE" ]; then
  hydra_action_usage
  exit 1
fi

hydra_backup_environment $1 restore

# Check if folder exist on the backup
if [ ! -d "$RESTOREDIR/$FOLDER" ]; then
  echo "Folder $FOLDER does not exist at restored backup $RESTOREDIR"
  exit 1
fi

# Check if there's already a site folder and backup it
if [ -e "$FOLDER" ]; then
  echo "Folder $FOLDER already exists, backing it up first..."
  hydractl backup-site $SITE
  if [ "$?" != "0" ]; then
    echo "Error backing up $FOLDER"
    exit 1
  else
    echo "Erasing old site folder"
    rm -rf $FOLDER
  fi
fi

# Copy site folder from backup
echo "Copying site $SITE from backup $RESTOREDIR..."
cp -a $RESTOREDIR/$FOLDER $FOLDER

# Fix permissions
chown -R root.root $FOLDER

# Trac
if [ -e "$FOLDER/trac" ]; then
  ( cd $FOLDER/trac && chown -R $SITE.$SITE attachments conf db auth plugins .egg-cache )
fi

# PmWiki
if [ -e "$FOLDER/wiki" ]; then
  ( cd $FOLDER/wiki && chown -R $SITE.$SITE wiki.d uploads )
  chown $SITE.root $FOLDER/wiki/local/config.php
  chmod 660 $FOLDER/wiki/local/config.php
fi

# Site
if [ -e "$FOLDER/site" ]; then
  chown -R $SITE.$SITE $FOLDER/site
fi

# Drupal
if [ -e "$FOLDER/drupal" ]; then
  # TODO: how to check drupal series?
  # TODO: check symlinks
  # TODO: database import
  chown root.$SITE $FOLDER/drupal/settings.php
  chmod 640 $FOLDER/drupal/settings.php
fi

# Restore database
if [ -f "$RESTOREDIR/var/backups/mysql/sqldump/$SITE.sql.gz" ]; then
  BASEDIR="$FOLDER"
  hydra_set_tmpfile $SITE -d
  cp $RESTOREDIR/var/backups/mysql/sqldump/$SITE.sql.gz $TMPWORK
  ( cd $TMPWORK && gunzip $SITE.sql.gz )
  hydra_truncate_database $SITE
  mysql $SITE < $TMPWORK.sql
  hydra_unset_tmpfile $TMPWORK
else
  echo "Databases should be manually restored"
fi