source: alternc/trunk/src/sqlbackup.sh @ 2178

Revision 2178, 2.9 KB checked in by anarcat, 5 years ago (diff)

correctly declare functions, we were missing parenthesis

  • Property svn:executable set to *
Line 
1#!/bin/sh
2
3# $Id: sqlbackup.sh,v 1.9 2005/05/04 16:20:14 anarcat Exp $
4# ----------------------------------------------------------------------
5# AlternC - Web Hosting System
6# Copyright (C) 2002 by the AlternC Development Team.
7# http://alternc.org/
8# ----------------------------------------------------------------------
9# Based on:
10# Valentin Lacambre's web hosting softwares: http://altern.org/
11# ----------------------------------------------------------------------
12# LICENSE
13#
14# This program is free software; you can redistribute it and/or
15# modify it under the terms of the GNU General Public License (GPL)
16# as published by the Free Software Foundation; either version 2
17# of the License, or (at your option) any later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22# GNU General Public License for more details.
23#
24# To read the license please visit http://www.gnu.org/copyleft/gpl.html
25# ----------------------------------------------------------------------
26# Original Author of file: Benjamin Sonntag - 2003-03-23
27# Purpose of file: MySQL Database backup shell script for AlternC
28# ----------------------------------------------------------------------
29
30set -e
31
32dobck() {
33    local ext
34    local i
35    local old_ifs
36
37    # mysql -B uses tab as a separator between fields, so we have to mess
38    # with IFS in order to get the correct behaviour
39    old_ifs="$IFS"
40    IFS="       "
41    while read login pass db count compressed target_dir; do
42        IFS="$old_ifs"
43
44        if [ "$compressed" -eq 1 ]; then
45            ext=".gz"
46        else
47            ext=""
48        fi
49        i="$count"
50       if [ ! -d "$target_dir" ] ; then
51               echo "$target_dir is not a directory, skipping" >&2
52               continue
53       fi
54        while [ "$i" -gt 1 ]; do
55          next_i=$(($i - 1))
56          mv -f "${target_dir}/${db}.sql.${next_i}${ext}" \
57                "${target_dir}/${db}.sql.${i}${ext}" 2>/dev/null || true
58          i=$next_i # loop should end here
59        done
60        mv -f "${target_dir}/${db}.sql${ext}" \
61              "${target_dir}/${db}.sql.${i}${ext}" 2>/dev/null || true
62        if [ "$compressed" -eq 1 ]; then
63            mysqldump --defaults-file=/etc/alternc/my.cnf ${db} --add-drop-table --allow-keywords -Q -f -q -a -e |
64                gzip -c > "${target_dir}/${db}.sql${ext}"
65        else
66            mysqldump --defaults-file=/etc/alternc/my.cnf ${db} --add-drop-table --allow-keywords -Q -f -q -a -e \
67                > "${target_dir}/${db}.sql"
68        fi
69
70        IFS="   "
71    done
72    IFS="$old_ifs"
73}
74
75if [ "$1" = "daily" ]; then
76    # Daily :
77    mode=2
78else
79    # weekly:
80    mode=1
81fi
82
83/usr/bin/mysql --defaults-file=/etc/alternc/my.cnf -B << EOF | tail -n '+2' | dobck
84SELECT login, pass, db, bck_history, bck_gzip, bck_dir
85  FROM db
86 WHERE bck_mode=$mode;
87EOF
88
89# vim: et sw=4
Note: See TracBrowser for help on using the repository browser.