Script bash per fare il backup di un sito Drupal con database SQLite

Script per effettuare il backup tramite ftp di un sito Drupal che usa un database SQLite e per poi archiviarlo.

backup_site.sh:

#!/bin/bash
# License: GPL
#
# Author: Mentor <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
HOST='ftp.site.com'
USER='username'
PASSWORD='password'

BACKUPDIR=$HOME'/backup/site'
WORKINGDIR='/tmp'

DBPATH='sites/default/files'
DBNAME='.ht.sqlite'

cd $WORKINGDIR

wget -m --preserve-permissions --user=$USER --password=$PASSWORD ftp://$HOST

sqlite3 $HOST/$DBPATH/$DBNAME "VACUUM;"
while [ $? -ne 0 ]; do
    wget -m --preserve-permissions --user=$USER --password=$PASSWORD ftp://$HOST/$DBPATH/$DBNAME
    sqlite3 $HOST/$DBPATH/$DBNAME "VACUUM;"
done

mkdir -p "$BACKUPDIR"
7z a -mhe -p$PASSWORD "$BACKUPDIR/$HOST-`date +%Y%m%dT%H%M`.7z" "$HOST"

rm -r $HOST

Lo script può essere eseguito via cron in questo modo:

0 20 1 * * bin/backup_site.sh >> bin/cron.log 2>&1

 

Section: 

Commenti

Aggiungi un commento