Your IP : 216.73.216.40


Current Path : /proc/self/root/Data/.backup/script/
Upload File :
Current File : //proc/self/root/Data/.backup/script/datestamp_backups.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'

RSNAP_INTS = 'dayago', 'weekago', 'monthago'



date_dir = os.path.join(RSNAP_ROOT, 'date')
#date_dir = os.path.join(RSNAP_ROOT)



# get the date

today = date.today()

stamp = today.isoformat()



# put date in the top level of the current backup (dayago.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)