Created
December 2, 2011 21:22
-
-
Save luisuribe/1424888 to your computer and use it in GitHub Desktop.
poor man's backup
This file contains hidden or 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
| petunia:~/scripts# cat psql.sh | |
| #!/bin/bash | |
| # Location of the backup logfile. | |
| timeslot=`date +%d-%m-%Y` | |
| # Location to backups. | |
| backup_dir="/backups/" | |
| mkdir -p $backup_dir/$timeslot/psql | |
| backup_dst=$backup_dir/$timeslot/psql | |
| logfile="$backup_dst/logfile.log" | |
| md5file="$backup_dst/md5sum.txt" | |
| touch $logfile $md5file | |
| databases=`psql -h localhost -U postgres -q -c "\l" | sed -n 4,/\eof/p | grep -v rows\) | awk {'print $1'} ` | |
| for i in $databases; do | |
| timeinfo=`date '+%T %x'` | |
| echo "Backup and Vacuum complete at $timeinfo for time slot $timeslot on database: $i " >> $logfile | |
| #/server/pgsql/bin/vacuumdb -z -h localhost -U postgres $i >/dev/null 2>&1 | |
| /usr/bin/pg_dump $i -h localhost -U postgres | gzip > "$backup_dst/$timeslot-$i-database.sql.gz" | |
| done | |
| #------------------------------------------------- | |
| cd $backup_dst | |
| cat /dev/null > $md5file | |
| checksum=`ls -c1 $backup_dst` | |
| for x in $checksum; do | |
| echo "Making checksum each file: $x" >> $logfile | |
| /usr/bin/md5sum $x >> $md5file | |
| done | |
| petunia:~/scripts# cat directorios.sh | |
| #!/bin/bash | |
| # Make folder with date to order data | |
| timeslot=`date +%d-%m-%Y` | |
| backup_dir="/backups/" | |
| mkdir -p $backup_dir/$timeslot/directorios | |
| backup_dst=$backup_dir/$timeslot/directorios | |
| logfile=$backup_dst/logfile.log | |
| md5file="$backup_dst/md5sum.txt" | |
| touch $logfile $md5file | |
| # Path folders backup | |
| backupfiles_path='/etc/ /opt/ /var/www /var/log' | |
| for i in $backupfiles_path; do | |
| timeinfo=`date '+%T %x'` | |
| echo "Backup complete at $timeinfo for time slot $timeslot on directories: $i " >> $logfile | |
| nombre=`echo $i|sed -e 's/\///g'` | |
| echo $nombre | |
| tar czf $backup_dst/$timeslot-$nombre.tar.gz $i | |
| done | |
| #------------------------------------------------- | |
| cd $backup_dst | |
| cat /dev/null > $md5file | |
| checksum=`ls -c1 $backup_dst` | |
| for x in $checksum; do | |
| echo "Making checksum each file: $x" >> $logfile | |
| /usr/bin/md5sum $x >> $md5file | |
| done | |
| #mail -s "[Backup result $timeslot]" foo@bar.com < md5sum.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment