Supprimer un message
zion
Un script que j'avais trouvé il y a longtemps, que j'ai utilisé quelques temps et modifié à ma guise. Il n'y a pas de fichier de config mais tu verras c'est ultra simple
#! /bin/bash
#
# creates backups of essential files
#
DATA="/home/ /root /var/www/html /var/spool/mail"
CONFIG="/etc /var/cache /usr/local/bin"
LIST="/tmp/backlist_$$.txt"
DATE_START=`date`
#
set $(date)
#
if test "$1" = "Sun" ; then
# weekly a full backup of all data and config. settings:
#
tar cfz "/backup/data/$6-$2-$3_data_full.tgz" $DATA
#rm -f /backup/data/data_diff*
#
tar cfz "/backup/config/$6-$2-$3_config_full.tgz" $CONFIG
#rm -f /backup/config/config_diff*
BACK_TYPE="Full Backup"
else
# incremental backup:
#
find $DATA -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
tar cfzT "/backup/data/$6-$2-$3_data_diff.tgz" "$LIST"
rm -f "$LIST"
#
find $CONFIG -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
tar cfzT "/backup/config/$6-$2-$3_config_diff.tgz" "$LIST"
rm -f "$LIST"
BACK_TYPE="Incremental Backup"
fi
#
# create sql dump of databases:
mysqldump -u root --opt unebase > "/backup/database/temp/$6-$2-$3_db_unebase.sql"
mysqldump -u root --all-databases > "/backup/database/temp/$6-$2-$3_db_all.sql"
# gzip databases dump
gzip "/backup/database/temp/$6-$2-$3_db_unebase.sql"
gzip "/backup/database/temp/$6-$2-$3_db_all.sql"
tar -cf /backup/database/$6-$2-$3_db.tar /backup/database/temp/*
rm -f /backup/database/temp/*
# Upload to home
tar -cf /backup/ftp/p4_$6-$2-$3.tar /backup/database/$6-$2-$3* /backup/config/$6-$2-$3* /backup/data/$6-$2-$3*
#scp -B /backup/ftp/p4_$6-$2-$3.tar backup@yourhostname.com:p4_$6-$2-$3.tar
ftp -n -v yourhostname.com <<EOF
user tonlogin tonpassword
lcd /backup/ftp
binary
cd HD_a2/p4
put p4_$6-$2-$3.tar
quit
EOF
rm -f /backup/ftp/*
rm -f /backup/config/*
rm -f /backup/database/*
rm -f /backup/data/*
C'est rudimentaire mais tu peux partir d'un truc comme ça
#! /bin/bash
#
# creates backups of essential files
#
DATA="/home/ /root /var/www/html /var/spool/mail"
CONFIG="/etc /var/cache /usr/local/bin"
LIST="/tmp/backlist_$$.txt"
DATE_START=`date`
#
set $(date)
#
if test "$1" = "Sun" ; then
# weekly a full backup of all data and config. settings:
#
tar cfz "/backup/data/$6-$2-$3_data_full.tgz" $DATA
#rm -f /backup/data/data_diff*
#
tar cfz "/backup/config/$6-$2-$3_config_full.tgz" $CONFIG
#rm -f /backup/config/config_diff*
BACK_TYPE="Full Backup"
else
# incremental backup:
#
find $DATA -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
tar cfzT "/backup/data/$6-$2-$3_data_diff.tgz" "$LIST"
rm -f "$LIST"
#
find $CONFIG -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
tar cfzT "/backup/config/$6-$2-$3_config_diff.tgz" "$LIST"
rm -f "$LIST"
BACK_TYPE="Incremental Backup"
fi
#
# create sql dump of databases:
mysqldump -u root --opt unebase > "/backup/database/temp/$6-$2-$3_db_unebase.sql"
mysqldump -u root --all-databases > "/backup/database/temp/$6-$2-$3_db_all.sql"
# gzip databases dump
gzip "/backup/database/temp/$6-$2-$3_db_unebase.sql"
gzip "/backup/database/temp/$6-$2-$3_db_all.sql"
tar -cf /backup/database/$6-$2-$3_db.tar /backup/database/temp/*
rm -f /backup/database/temp/*
# Upload to home
tar -cf /backup/ftp/p4_$6-$2-$3.tar /backup/database/$6-$2-$3* /backup/config/$6-$2-$3* /backup/data/$6-$2-$3*
#scp -B /backup/ftp/p4_$6-$2-$3.tar backup@yourhostname.com:p4_$6-$2-$3.tar
ftp -n -v yourhostname.com <<EOF
user tonlogin tonpassword
lcd /backup/ftp
binary
cd HD_a2/p4
put p4_$6-$2-$3.tar
quit
EOF
rm -f /backup/ftp/*
rm -f /backup/config/*
rm -f /backup/database/*
rm -f /backup/data/*
C'est rudimentaire mais tu peux partir d'un truc comme ça