PostgreSQL backup script deleted 3 days ago Backup while compressing yesterday backup

Source: Internet
Author: User
Tags postgresql backup

Scripting Features:

System environment: SUSE Linux Server 11.3 X64

1. Delete compressed files (. bak.tar.gz) 3 days ago

2. Back up the database (uncompressed file. bak)

3. Compress yesterday database backup file (. bak.tar.gz), delete yesterday database backup uncompressed file (. bak)


#!/bin/bash

Export path= $PATH:/usr/local/pgsql/bin

Date= ' Date +%y_%m_%d_%h '

Yesday= ' date-d "Yesterday" +%y_%m_%d_%h '

Twodago= ' date-d ' 3 day ago "+%y_%m_%d_%h"

Pghome= "/home/postgres"

CD $PGHOME


echo "Dir list before delete 3 day ago backup file:"

Ls-lrt


# # # Delete 3 day ago backup File # # # #

Tdafile= "Testdb_" $TWODAGO ". bak.tar.gz"

echo "Detele 3 day ago File:" $TDAFILE

RM "$TDAFILE"

echo "Dir list after delete 3 day ago backup file:"

Ls-lrt


# # # Backup Ape Database # # #


Echo $DATE

echo "Starting Backup database:ape ...."

Su-postgres-c "Pg_dump testdb >/home/postgres/testdb_$date.bak"

reval=#?

If reval=0

Then

echo "Database TestDB backup successful!"

Else

echo "Database TestDB backup failed!"

Fi


echo "Dir list after backup database TestDB:"

Ls-lrt


# # # Compress and remove yesterday bak file####

Comfile= "Testdb_" $YESDAY ". bak.tar.gz"

Ydfile= "Testdb_" $YESDAY ". Bak"

echo "Tar zcvf $COMFILE $YDFILE" |sh

echo "General yesterday tar file:" $COMFILE

RM "$YDFILE"

echo "Delete yesterday file:" $YDFILE

echo "Dir list after tar yesterday backup file:"

Ls-lrt


Find/home/postgres-mtime +3-name "*.bak"-exec rm-rf {} \;

Find/home/postgres-mtime +3-name "*.bak.tar.gz"-exec rm-rf {} \;


This article is from the "Yiyi" blog, make sure to keep this source http://heyiyi.blog.51cto.com/205455/1658896

PostgreSQL backup script deleted 3 days ago Backup while compressing yesterday backup

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.