summaryrefslogtreecommitdiffstats
path: root/backup.sh
blob: 24009d92c0ec222a5d9c95bebe0c6f8079f5d933 (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
#!/bin/bash

# notes
# $0 is visible globally, in functions too

# apparently su -c accepts a command and 1 argument
CMDL_ARGS=$@
export CMDL_ARGS

chk_root()
{
    if [[ ! $(id -u) -eq 0 ]]; then
        echo "root user required";
        # exec works similar to fork()
        exec su -c "\"$0\" $CMDL_ARGS"
        exit $?
    fi
}

chk_root $@
date=$(date +%m.%d.%y)

echo "backing up mysql"
#mysqldump -u root -p drupal > db-drupal-${date}.sql

echo "backing up /srv"
tar -cvjf http-${date}.tar.bz2 /srv/http
tar -cvjf git-${date}.tar.bz2 /srv/git