Created
December 7, 2008 01:21
-
-
Save agile/33005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
DIR=`dirname $0` | |
progname=`basename $0` | |
PRG=`cd $DIR; pwd `/$progname | |
if [ -r /etc/default/backup_etc ] | |
then | |
. /etc/default/backup_etc | |
fi | |
etc_backup_enable=${etc_backup_enable:-"NO"} | |
etc_backup_dir=${etc_backup_dir:-"/home/archives/$(hostname)/etc"} | |
etc_backup_savedays=${etc_backup_savedays:-"7"} | |
case $etc_backup_enable in | |
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) | |
exit 1 | |
;; | |
esac | |
if [ ! -d "$etc_backup_dir" ] ; then | |
echo "Creating $etc_backup_dir" | |
mkdir -p $etc_backup_dir | |
fi | |
umask 077 | |
now=`date "+%Y-%m-%dT%H%M%S"` | |
`cd /; tar zcf $etc_backup_dir/etc_${now}.tgz etc` | |
# cleaning up old data | |
find $etc_backup_dir -name 'etc_*' -a -mtime +$etc_backup_savedays -delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
DIR=`dirname $0` | |
progname=`basename $0` | |
PRG=`cd $DIR; pwd `/$progname | |
if [ -r /etc/default/backup_home ] | |
then | |
. /etc/default/backup_home | |
fi | |
home_backup_enable=${home_backup_enable:-"NO"} | |
home_backup_dir=${home_backup_dir:-"/home/archives/$(hostname)/home"} | |
home_backup_savedays=${home_backup_savedays:-"7"} | |
case $home_backup_enable in | |
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) | |
echo "not enabled" | |
exit 1 | |
;; | |
esac | |
if [ ! -d "$home_backup_dir" ] ; then | |
echo "Creating $home_backup_dir" | |
mkdir -p $home_backup_dir | |
fi | |
umask 077 | |
now=`date "+%Y-%m-%dT%H%M%S"` | |
`cd /; tar zcf $home_backup_dir/home_${now}.tgz --exclude "home/archives" home` | |
`cd /; tar zcf $home_backup_dir/root_${now}.tgz root` | |
# cleaning up old data | |
find $home_backup_dir -name 'home_*' -a -mtime +$home_backup_savedays -delete | |
find $home_backup_dir -name 'root_*' -a -mtime +$home_backup_savedays -delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! /bin/bash | |
# Maintenance shell script to backup mysql databases | |
###################################################################### | |
# | |
# Implementation notes: | |
# | |
# 1) The script filters db's with names "Database" and "backups" since | |
# mysql treats every subdir under "base dbdir" as potential db-dir | |
# 2) The default mysql database directory is possibly not /var/db/mysql | |
# But IMHO it would be a good thing | |
# 3) The default mysql "super-user" with all rights is possibly not | |
# "root" user. It might be "mysql", I don't remember the defaults. | |
# | |
###################################################################### | |
DIR=`dirname $0` | |
progname=`basename $0` | |
PRG=`cd $DIR; pwd `/$progname | |
if [ -r /etc/default/backup_mysql ] | |
then | |
. /etc/default/backup_mysql | |
fi | |
# set defaults | |
mysql_backup_enable=${mysql_backup_enable:-"NO"} | |
mysql_db_user=${mysql_db_user:-"root"} | |
mysql_db_passwd=${mysql_db_passwd:-"dbpasswd"} | |
mysql_db_host=${mysql_db_host:-"localhost"} | |
mysql_backup_dir=${mysql_backup_dir:-"/home/archives/$(hostname)/mysql"} | |
mysql_backup_savedays=${mysql_backup_savedays:-"7"} | |
mysql_args=${mysql_args:-\ | |
"-u$mysql_db_user -p$mysql_db_passwd -h$mysql_db_host"} | |
mysql_dump_args=${mysql_dump_args:-\ | |
"-u$mysql_db_user -p$mysql_db_passwd -h$mysql_db_host"} | |
case $mysql_backup_enable in | |
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) | |
exit 1 | |
;; | |
esac | |
# MySQL Hostname | |
DBHOST='localhost' | |
# Run as mysql super user | |
if [ `id -un` != $mysql_db_user ]; then | |
su -l $mysql_db_user -c ${PRG} | |
exit $? | |
fi | |
# $mysql_backup_dir must be writeable by db user | |
if [ ! -d "$mysql_backup_dir" ] ; then | |
echo "Creating $mysql_backup_dir" | |
mkdir -p $mysql_backup_dir | |
fi | |
# Protect the data | |
umask 077 | |
dbnames=`mysql ${mysql_args} -e"show databases"` | |
rc=$? | |
now=`date "+%Y-%m-%dT%H%M%S"` | |
for db in ${dbnames}; do | |
if [ "$db" != "Database" -a "$db" != "backups" ]; then | |
#echo -n " $db" | |
file=$mysql_backup_dir/mysqldump_${db}_${now}.gz | |
mysqldump ${mysql_dump_args} ${db} | gzip --best > $file | |
[ $? -gt 0 ] && rc=3 | |
fi | |
done | |
if [ $rc -gt 0 ]; then | |
echo | |
echo "Errors were reported during backup." | |
fi | |
# cleaning up old data | |
find $mysql_backup_dir -name 'mysqldump_*' -a -mtime +$mysql_backup_savedays -delete | |
exit $rc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Maintenance shell script to vacuum and backup database | |
# If there is a global system configuration file, suck it in. | |
if [ -r /etc/default/backup_postgres ] | |
then | |
. /etc/default/backup_postgres | |
fi | |
# Establish defaults | |
daily_postgres_backup_enable=${daily_postgres_backup_enable:-"NO"} # do backup | |
daily_postgres_vacuum_enable=${daily_postgres_vacuum_enable:-"NO"} # do vacuum | |
daily_postgres_vacuum_args=${daily_postgres_vacuum_args:-"-z"} | |
daily_postgres_pgdump_args=${daily_postgres_pgdump_args:-"-b -F c"} | |
# backupdir is relative to ~postgres home directory unless it begins with a slash: | |
daily_postgres_backupdir=${daily_postgres_backupdir:-"/home/archives/$(hostname)/postgres"} | |
daily_postgres_savedays=${daily_postgres_savedays:-"7"} | |
# allow '~<B4> in dir name | |
eval backupdir=${daily_postgres_backupdir} | |
rc=0 | |
case "$daily_postgres_backup_enable" in | |
[Yy][Ee][Ss]) | |
# daily_postgres_backupdir must be writeable by user postgres | |
# ~postgres is just that under normal circumstances, | |
# but this might not be where you want the backups... | |
if [ ! -d ${backupdir} ] ; then | |
echo Creating ${backupdir} | |
mkdir ${backupdir}; chmod 700 ${backupdir}; chown postgres ${backupdir} | |
fi | |
echo | |
echo "PostgreSQL maintenance" | |
# Protect the data | |
umask 077 | |
dbnames=`su -l postgres -c "psql -q -t -A -d template1 -c SELECT\ datname\ FROM\ pg_database\ WHERE\ datname!=\'template0\'"` | |
rc=$? | |
now=`date "+%Y-%m-%dT%H:%M:%S"` | |
file=${daily_postgres_backupdir}/pgglobals_${now} | |
su -l postgres -c "pg_dumpall -g | gzip -9 > ${file}.gz" | |
for db in ${dbnames}; do | |
echo -n " $db" | |
file=${backupdir}/pgdump_${db}_${now} | |
su -l postgres -c "pg_dump ${daily_postgres_pgdump_args} -f ${file} ${db}" | |
[ $? -gt 0 ] && rc=3 | |
done | |
if [ $rc -gt 0 ]; then | |
echo | |
echo "Errors were reported during backup." | |
fi | |
# cleaning up old data | |
find ${backupdir} \( -name 'pgdump_*' -o -name 'pgglobals_*' \) \ | |
-a -mtime +${daily_postgres_savedays} -delete | |
;; | |
esac | |
case "$daily_postgres_vacuum_enable" in | |
[Yy][Ee][Ss]) | |
echo | |
echo "vacuuming..." | |
su -l postgres -c "vacuumdb -a -q ${daily_postgres_vacuum_args}" | |
if [ $? -gt 0 ] | |
then | |
echo | |
echo "Errors were reported during vacuum." | |
rc=3 | |
fi | |
;; | |
esac | |
exit $rc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment