2 # Filename: dirvish-setup
3 # Purpose: create basic setup for dirvish(8)
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 # http://apt-get.dk/howto/backup/
10 # http://edseek.com/~jasonb/articles/dirvish_backup/advanced.html
11 # http://www.dirvish.org/svn/contrib/admin/DailyEmailScript/dirvish-status.sh
12 ################################################################################
16 # shellcheck disable=SC1091
17 . /etc/grml/script-functions
18 # shellcheck disable=SC1091
19 . /etc/grml/lsb-functions
22 check4progs dialog dirvish rsync ssh-keygen ssh-copy-id
25 CONFFILE=/etc/dirvish/master.conf
30 if [ -f "$CONFFILE" ] ; then
31 MASTERINFO="Notice: $CONFFILE exists already so I will not touch it.
32 Please do not forget to add $CLIENT to the file if you wan to use the 'Runall' functionality."
34 MASTERINFO="An initial master configuration ($CONFFILE) has been generated.
35 Please adjust it according to your needs."
36 cat > $CONFFILE << EOF
37 # Master configuration file for dirvish, created by $PN on $(date)
48 # var/cache/apt/archives
54 # .firefox/default/*/Cache/*
58 # add-another-client-here 22:00
60 # See http://www.dirvish.org/debian.howto.html for further details:
61 expire-default: +30 days
63 # MIN HR DOM MON DOW STRFTIME_FMT
68 # * * * * 2-7 +15 days
76 # shellcheck disable=SC1090
77 test -f "${HOME}/.keychain/$(uname -n)-sh" && . "${HOME}/.keychain/$(uname -n)-sh"
81 # prompt user for directory which should be used
82 BACKUP_DIR="$(dialog --stdout --inputbox 'Please choose the directory where backups should be placed' 0 0 /backups)"
84 if ! [ -d "$BACKUP_DIR" ] ; then
85 dialog --stdout --title "${PN}" --yesno "The directory $BACKUP_DIR does not yet exist. Do you want me to create it for you? " 0 0
88 if [ ${RC} -eq 0 ]; then
89 echo "mkdir $BACKUP_DIR"
90 echo "chmod 700 $BACKUP_DIR"
92 echo "warning: $BACKUP_DIR does not exist, skipped creation as requested"
98 CLIENT="$(dialog --stdout --inputbox 'Please choose the name for your client instance, also known as vault' 0 0 client1)"
102 TREE="$(dialog --stdout --inputbox 'Please choose the directory you want to backup from your client (also known as tree)' 0 0 /home)"
105 create_client_conf() {
106 mkdir -p "${BACKUP_DIR}/${CLIENT}/dirvish"
107 if [ -f "${BACKUP_DIR}/${CLIENT}/dirvish/default.conf" ] ; then
108 ewarn "Warning: ${BACKUP_DIR}/${CLIENT}/dirvish/default.conf exists already, ignoring creation." ; eend 0
110 cat > "${BACKUP_DIR}/${CLIENT}/dirvish/default.conf" << EOF
111 # Configuration file of client-side for dirvish created by $PN on $(date)
116 image-default: %Y-%m-%d
118 var/cache/apt/archives/*
122 rsh: ssh -i $HOME/.ssh/id_rsa_dirvish_${CLIENT}
128 CLIENTNAME="$(dialog --stdout --inputbox 'Please choose user login and hostname for the client you want to backup. Syntax: user@host' 0 0 root@"$(hostname)")"
130 dialog --stdout --title "${PN}" --yesno "Do you want me to create ssh setup for client ${CLIENTNAME} using ssh-keygen and ssh-copy-id?" 0 0
133 if [ ${RC} -eq 0 ]; then
134 [ -d "$HOME/.ssh" ] || mkdir "$HOME/.ssh"
135 einfo "Creating $HOME/.ssh/id_rsa_dirvish_${CLIENT} using ssh-keygen:"
136 ssh-keygen -t rsa -f "$HOME/.ssh/id_rsa_dirvish_${CLIENT}" ; eend $?
137 einfo "Running ssh-copy-id to copy ssh key to $CLIENTNAME:"
138 ssh-copy-id -i "$HOME/.ssh/id_rsa_dirvish_${CLIENT}.pub" "$CLIENTNAME" ; eend $?
143 dialog --stdout --title "${PN}" --yesno "Do you want to backup $CLIENT via network? Answering with no will use localhost [$(hostname)] as client." 0 0
146 if [ ${RC} -eq 0 ]; then
149 CLIENTNAME=$(hostname) # use localhost only
154 einfo "Running $PN was successful. Enjoy using dirvish!" ; eend 0
156 einfo "Please adjust ${BACKUP_DIR}/${CLIENT}/dirvish/default.conf according to your needs.
158 Then run the following command to create an initial backup:
160 dirvish --summary long --vault $CLIENT --init
162 Find the backup inside $BACKUP_DIR/$CLIENT/$(date +%Y-%m-%d)/tree/ then.
164 Documentation available at:
166 man dirvish-locate.1 dirvish.conf.5 dirvish.8 dirvish-runall.8 dirvish-expire.8
167 /usr/share/doc/dirvish/HOWTO.upstream /usr/share/doc/dirvish/FAQ.html
168 /usr/share/doc/dirvish/HOWTO.Debian.gz
170 http://www.dirvish.org/
171 http://wiki.dirvish.org/
173 Please report bugs regarding ${PN}: http://grml.org/bugs/
179 echo "Usage: $PN" 1>&2
184 # now run the functions:
189 create_client_conf && \
193 ## END OF FILE #################################################################
194 # vim: ft=sh ai tw=80 expandtab