| Current Path : /Data/.backup/script/ |
| Current File : //Data/.backup/script/website.iiita.ac.in.py |
#!/usr/bin/env python
# Copyright (C) 2009 by Terry Hancock
#---------------------------------------------------------------------------------------
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#---------------------------------------------------------------------------------------
#-- Datestamp Index for Backups --
from datetime import date
import os, glob
RSNAP_ROOT = '/Backup/data/rawbackup/website.iiita.ac.in'
RSNAP_INTS = 'dayago', 'weekago', 'monthago'
date_dir = os.path.join(RSNAP_ROOT, 'date')
# get the date
today = date.today()
#stamp = today.isoformat()
stamp = today.strftime("%d-%m-%Y")
# put date in the top level of the current backup (daily.0)
os.remove(os.path.join(RSNAP_ROOT, 'dayago.0', 'DATE'))
open(os.path.join(RSNAP_ROOT, 'dayago.0', 'DATE'), 'wt').write(stamp+'\n')
# delete the old index entries
os.system('rm -r %s' % os.path.join(RSNAP_ROOT, 'date'))
os.mkdir(os.path.join(RSNAP_ROOT, 'date'))
#for symlink in os.listdir(date_dir):
# os.remove(os.path.join(date_dir, symlink))
# read dates in all backups and write out symlinks for them as new index
append = 'bcdefghijklmnopqrstuvwxyz'
for interval in RSNAP_INTS:
for dirname in glob.glob(os.path.join(RSNAP_ROOT, '%s.*'%interval)):
directory = os.path.join(RSNAP_ROOT, dirname)
datestamp = open(os.path.join(directory, 'DATE'),'rt').read().strip()
target = os.path.join(date_dir, datestamp)
i=0
while os.path.exists(target):
target = os.path.join(date_dir, datestamp + append[i])
i += 1
os.symlink(directory, target)