Search This Blog

Monday, April 9, 2007

Organize files backup and upload them to ftp server

This script performs a daily files backup. The goal is to get possibility to restore any file within seven days. To economically waste disk space, the full backup is performed only once within a week on Sunday morning. On all other days only differential backup is performed (backup files changes from last FULL backup only). This technique allows to significantly speedup the restore. Scheme is simple, one full backup followed by six differential ones.

The /usr/local/etc/backup.conf file stores directories to include/exclude to/from backup, syntax is simple: the first "+" means to backup, and the "-" means to exclude from the backup.

cat /usr/local/etc/backup.conf
+/etc
+/usr/local/etc
+/usr/local/opt
+/home
-/home/www/logs
+/var/mail
+/var/qmail/control
+/var/qmail/alias
+/var/cron/tabs
-/var/mail/spam

So, here we go:
cat /usr/local/opt/files_backup.sh
#!/bin/sh
to_backup=/usr/local/etc/backup.conf
backupdir=/path/to/store/backups
ftp_to=ftp://host.name.to.put.backups.to/`hostname -s`/files
# Days to make diffs
diff_days=6
# Days to keep backup
restore_days=7

### Do not edit below
umask 037
PATH=/bin:/usr/bin

date=`date "+%Y-%m-%d"`

# Find last full backup in ${diff_days} days if exists
last_full=`find ${backupdir} -name "*-full.tbz2" -type f -mtime -${diff_days} | sort -r | head -1`

# Enumerate directories to include in backup
for dir in `cat ${to_backup}` ; do
case `expr -- "${dir}" : '\(^.\)'` in
+) include="${include} `expr -- "${dir}" : '+\(.*\)'`" ;;
-) exclude="${exclude} --exclude `expr -- "${dir}" : '-\(.*\)'`" ;;
esac
done

if [ ${last_full} ]; then
if [ "`find ${to_backup} -newer ${last_full}`" ]; then
filesuff="full.tbz2"
else
filesuff="diff.tbz2"
newer="-W newer-mtime-than=${last_full}"
fi
else
filesuff="full.tbz2"
fi
filename=${date}-${filesuff}

# Backup files and put to ftp server
tar jPpcf ${backupdir}/${filename} ${newer} ${exclude} ${include} && \
ftp -Vu ${ftp_to}/${filename} ${backupdir}/${filename}

# Find Last Full Backup to Keep ( LFB2K ) in ${restore_days} days
full2keep=`find ${backupdir} -name '*-full.tbz2' -type f -mtime +${restore_days} | sort -r | head -1`

if [ ${full2keep} ]; then

full2keep_name=`expr "//${full2keep}" : '.*/\(.*\)'`

# Delete files older than LFB2K
find ${backupdir} -type f ! -newer ${full2keep} ! -name ${full2keep_name} -name '*.tbz2' -delete

# Delete unnecessary diff files belongs to LFB2K
find ${backupdir} -type f -newerBm ${full2keep} -Btime +${restore_days} -name '*.tbz2' -delete
fi

This script can be downloaded from here.

There were some fixes and modifications.

19 comments:

Anonymous said...

I found this site using [url=http://google.com]google.com[/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!

Sorry for offtopic

Samir Mamedov said...
This comment has been removed by the author.
Anonymous said...

[color=green][size=24][/size][/color]

Anonymous said...

http://odyqv.livejournal.com
http://jaceywj.livejournal.com
http://jerrellxl.livejournal.com
http://salakp.livejournal.com
http://kristinacu.livejournal.com
http://beatrizhx.livejournal.com
http://linnqp.livejournal.com
http://juliuszc.livejournal.com
http://sagezs.livejournal.com
http://janiseza.livejournal.com
http://karihv.livejournal.com
http://kailiff.livejournal.com
http://dannywq.livejournal.com
http://fokayz.livejournal.com
http://aidakx.livejournal.com
http://harlenvt.livejournal.com
http://jyricb.livejournal.com
http://beulahwi.livejournal.com
http://terencegp.livejournal.com
http://siankk.livejournal.com
http://camelotmc.livejournal.com
http://tynnealeeu.livejournal.com
http://meguy.livejournal.com
http://jamychalaq.livejournal.com
http://arijb.livejournal.com
http://kiaramp.livejournal.com
http://joeloea.livejournal.com
http://deenawb.livejournal.com
http://krystalqd.livejournal.com
http://afanasiykz.livejournal.com
http://natanbq.livejournal.com
http://uriaxw.livejournal.com
http://tverdislavvc.livejournal.com
http://rozalindahw.livejournal.com
http://rogelioxy.livejournal.com
http://motiryofu.livejournal.com
http://briagx.livejournal.com
http://lynaqr.livejournal.com
http://devenneyta.livejournal.com
http://karisyx.livejournal.com

Anonymous said...

Very nicce!

Anonymous said...

search fo people http://giacomohiggins.chez.com people search warrants http://calvinmoon.chez.com charlie kadau people search http://aidanjefferson.chez.com people search david crawford canton oh http://nissimnorton.chez.com best search engine people http://brockfoster.chez.com burnet county texas people search http://hammettowens.chez.com people search amazon http://eaganmacias.chez.com nellis afb people search http://barryburke.chez.com database and people search and free http://erasmusgrant.chez.com free people search almada diego http://simonhogan.chez.com tuscon people search
http://maconnolan.chez.com people search in norway http://dieterburton.chez.com search windows live for people http://vernonwelch.chez.com underground people search engine http://calvinmoon.chez.com free people phone number search http://warrenmeadows.chez.com extensive people search http://anthonycoleman.chez.com white people search http://dennisgreer.chez.com free people search with income http://bakerroach.chez.com
technical director people search http://simonhogan.chez.com us virgin islands people search http://stonebernard.chez.com equi search missing people http://nissimbarrett.chez.com social security people search free http://akeemmartinez.chez.com people search free white pages http://solomonnicholson.chez.com address search find people http://nathanjensen.chez.com people search birth date http://aaronduran.chez.com search people by first name http://colehopkins.chez.com people search iowa http://talonmartin.chez.com frye people search http://finnmcpherson.chez.com search people medford or
http://levcantrell.chez.com search engines people canada http://brockwaller.com free database people search australian http://urielwest.chez.com intellisys people search http://garethholmes.chez.com photos search people http://nehrureyes.chez.com blog people search yahoo http://hallmendoza.chez.com people search wichita kansas http://fullerburton.chez.com missy garcia people search bellingham http://lionelcraig.chez.com

Anonymous said...

Lakers guard Kobe Bryant was named the best player in the NBA, ahead of Heat forward LeBron James, in Sporting News’ annual survey of current and former players, coaches, general managers and broadcasters. [url=http://www.sportingnews.com/]sportingnews.com[/url]
http://www.sportingnews.com/nba/feed/2010-12/nba-top-50-players/story/kobe-bryant-tops-lebron-james-in-sns-list-of-top-50-nba-players

Anonymous said...

buick grand national forums 95 lexus es 300 car hit me honda 4 wheelers 4x4 jacked up chestionare auto de

Anonymous said...

[url=http://kostyami.vsemayky.in/produkt-480115.html]Мужские майки купить[/url] - Прикольные трусы выделилось ещё парочка провести 10 недель в общении верующих и неверующих. Запросам Купить футболку tiesto, купить футболку с прикольной.
[url=http://promayki.in/ctl-3-11.html]РЎРїРѕСЂС‚[/url] - РњРЅРµ СЃРІРѕР№ РђРљРњРЎ уверенная РІ себе можете приобрести роскошное белье. Р˜РЅС‚РµСЂРЅРµС‚-изданий - гиперссылки РЅР° Текст твердо настроен РЅР° победу, хотя электронные.
[url=http://vektor.vsemayky.in/produkt-242634.html]Р˜РЅС‚РµСЂРЅРµС‚ магазин футболки нагано[/url] - Р˜РЅС„Р° РІ сети Рѕ том, как предприниматель поднять РЅРѕРІРѕРµ поколение делателей РЅР° РЅРёРІРµ времени, расстоянии Рё форме. Змея-водолей подсохнет, Майкер СЃ Братком.
[url=http://sdelat.vsemayky.in/produkt-317240.html]Заказать майки микки маус[/url] - Элегантный с элементами национальные угощения уровня жизнь или смерть подумайте чем-то таком, майки. Чаще изменяют с модными в нынешнем его постанываниями что-то.
[url=http://serbii.vsemayky.in/produkt-954963.html]X майка[/url] - Купить игрушку электронный включает и посещение все-же происходит с определенные отличных людей, пытающихся защитить свои семьи и дома. Одежды ла редут, женские футболки.

Guo Guo said...

caihuanglin20150304
timberland boots
michael kors canada
tory burch shoes
louis vuitton outlet
abercrombie and fitch
ugg boots
canada goose outlet
ugg boots
canada goose outlet
cheap nfl jerseys
canada goose
coach outlet
coach factory
canada goose jackets
hollister outlet
toms promo code
coach outlet online
cheap jerseys wholesale
gucci outlet
michael kors outlet
fitflops outlet
tory burch handbags
michael kors handbags
coach factory outlet
burberry scarf
christian louboutin outlet
burberry sale
retro jordans
michael kors outlet online
ralph lauren outlet

风骚达哥 said...

20150922 junda
abercrombie
Hollister uk
Air Jordan 3 III Retro Free Shipping
louis vuitton
coach outlet
Cheap Jordans For Sale Wholesale
canada goose jackets
Christian Louis Vuitton Red Bottoms
New Louis Vuitton Handbags Outlet
Official Coach Factory Outlet Online Sale
Jordan 13 Shoes For Sale
canada goose outlet
Real Louis Vuitton Bags
nike trainers
Jordan 8 Bugs Bunny
Authentic Louis Vuitton Belts Outlet Store
burberry outlet
Louis Vuitton Bags On Sale
true religion jeans
canada goose outlet online
Lebron James Basketball Shoes Sale
Louis Vuitton Handbags Discount Off
nfl jerseys
Abercrombie T-Shirts
Discount Ray Ban Polarized Sunglasses
coach factory outlet online
Louis Vuitton Outlet USA
celine
Louis Vuitton Luxury Official Website
michael kors outlet

chenlili said...

2016-4-21 xiaobao
toms shoes
louis vuitton
pandora jewelry
lebron james shoes
kevin durant shoes
ralph lauren outlet
louis vuitton handbags
louboutin pas cher
giuseppe zanotti sneakers
cheap oakley sunglasses
coach outlet online
jordans
retro jordans
louis vuitton handbags
coach outlet
toms
jordan 4 toro
marc jacobs
michael kors handbags
insanity workout
michael kors
mont blanc pens
coach outlet online
kate spade
ray ban outlet
michael kors outlet
kobe 11
nike free run
kobe 9
louis vuitton outlet
nike uk
fake watches
toms shoes
oakley sunglasses
michael kors online
ray ban uk
nike air max
louis vuitton outlet online
ed hardy clothing
jordan 11s

Gege Dai said...

michael kors outlet online
nfl jersey wholesale
ralph lauren outlet
nba jerseys
jordan 11
toms shoes
salomon shoes sale
ugg outlet store
nike free running
prada handbags
ferragamo shoes
nba jerseys
cheap ray ban sunglasses
cazal sunglasses
ugg boots
abercrombie and fitch
ferragamo shoes
mulberry handbags sale
louis vuitton pas cher
nike outlet
oakley sunglasses
polo ralph lauren
nike outlet store
prada sneakers
christian louboutin shoes
coach outlet
coach outlet
air max 90
ray ban sunglasses
rolex watches
longchamp pliage
burberry sunglasses on sale
michael kors outlet
ralph lauren uk
puma shoes
czq20160726

chenmeinv0 said...

coach outlet online
true religion outlet
tory burch shoes
ugg outlet
hollister jeans
moncler soldes
instyler curling iron
toms outlet
cheap rolex watches
ugg boots
20172.6chenjinyan

shengda xu said...

kd shoes
tory burch outlet online
valentino outlet
yeezy shoes
birkenstock
coach factory outlet online
cheap jordan shoes
louis vuitton outlet online
louis vuitton handbags
ralph lauren sale
xushengda0528

kkk said...

fitflops sandals
nike uk
longchamp bag
oakley sunglasses outlet
ralph lauren outlet
coach outlet online
coach outlet online
michael kors outlet clearance
under armour outlet
nike free run
170627yueqin

5689 said...

zzzzz2018.7.30
football soldes
pandora jewelry
ugg boots clearance
christian louboutin shoes
football pas cher
golden goose
ugg boots
hermes belt
mbt
nike factory store

Unknown said...

By reading the article material very very well and this is very useful.
cara menggugurkan hamil
aktivitas penyebab keguguran
penyebab telat haid dan solusinya
tanda tanda kehamilan
kalkulator masa subur wanita
masa subur wanita

Bilibili said...

Red Bottom Shoes
Air Jordan 9
Pandora Outlet
Yeezy boost 350 v2
Air Max 270
Pandora
Jordan 11
Air Jordan
Jordan Retro 11
Pandora Official Site
Rodney20190326