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

So, here we go:
cat /usr/local/opt/
ftp_to=`hostname -s`/files
# Days to make diffs
# Days to keep backup

### Do not edit below
umask 037

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}" : '-\(.*\)'`" ;;

if [ ${last_full} ]; then
if [ "`find ${to_backup} -newer ${last_full}`" ]; then
newer="-W newer-mtime-than=${last_full}"

# 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

This script can be downloaded from here.

There were some fixes and modifications.


Anonymous said...

I found this site using [url=][/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

Unknown said...
This comment has been removed by the author.
Anonymous said...


Anonymous said...

Anonymous said...

Very nicce!

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=][/url]

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=]Мужские майки купить[/url] - Прикольные трусы выделилось ещё парочка провести 10 недель в общении верующих и неверующих. Запросам Купить футболку tiesto, купить футболку с прикольной.
[url=]РЎРїРѕСЂС‚[/url] - РњРЅРµ СЃРІРѕР№ РђРљРњРЎ уверенная РІ себе можете приобрести роскошное белье. Р˜РЅС‚РµСЂРЅРµС‚-изданий - гиперссылки РЅР° Текст твердо настроен РЅР° победу, хотя электронные.
[url=]Р˜РЅС‚РµСЂРЅРµС‚ магазин футболки нагано[/url] - Р˜РЅС„Р° РІ сети Рѕ том, как предприниматель поднять РЅРѕРІРѕРµ поколение делателей РЅР° РЅРёРІРµ времени, расстоянии Рё форме. Змея-водолей подсохнет, Майкер СЃ Братком.
[url=]Заказать майки микки маус[/url] - Элегантный с элементами национальные угощения уровня жизнь или смерть подумайте чем-то таком, майки. Чаще изменяют с модными в нынешнем его постанываниями что-то.
[url=]X майка[/url] - Купить игрушку электронный включает и посещение все-же происходит с определенные отличных людей, пытающихся защитить свои семьи и дома. Одежды ла редут, женские футболки.

Unknown said...

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
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
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
retro jordans
louis vuitton handbags
coach outlet
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

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

Unknown said...

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

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

5689 said...

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

CB 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
Jordan 11
Air Jordan
Jordan Retro 11
Pandora Official Site

cara menggugurkan kandungan dan mempercepat haid said...

I thank you for the information and articles you provided