def prepare(): # from this point we are sure we don't have to be careful # with local files/devices/disks/etc # we are going to work with local files, we need our path path = os.path.dirname(os.path.abspath(__file__)) cron = "{0}/cron.d/solr.cron".format(path) # and root's cron will be set accordingly as well os.system("/bin/sed 's:INSTALLPATH:{0}:' {1} | /usr/bin/crontab".format(path, cron)) # ok, ready to set up assets like bucket and volume # also, if we have a valid mount, we don't do anything if os.path.ismount(mountpoint) == False: try: # only try to create one if we have one if "" == snapshot or None == snapshot: raise Exception('metadata','empty snapshot') else: create_device(snapshot) except: try: latest = administration.get_latest_snapshot(key, access, name) create_device(latest) except: create_device() os.system("/bin/chown -R fashiolista.fashiolista {0}".format(mountpoint))
def prepare(): # from this point we are sure we don't have to be careful # with local files/devices/disks/etc # we are going to work with local files, we need our path path = os.path.dirname(os.path.abspath(__file__)) cron = "{0}/cron.d/solr.cron".format(path) # and root's cron will be set accordingly as well os.system( "/bin/sed 's:INSTALLPATH:{0}:' {1} | /usr/bin/crontab".format( path, cron)) # ok, ready to set up assets like bucket and volume # also, if we have a valid mount, we don't do anything if os.path.ismount(mountpoint) == False: try: # only try to create one if we have one if "" == snapshot or None == snapshot: raise Exception('metadata', 'empty snapshot') else: create_device(snapshot) except: try: latest = administration.get_latest_snapshot( key, access, name) create_device(latest) except: create_device() os.system( "/bin/chown -R fashiolista.fashiolista {0}".format(mountpoint))
def prepare(): log('prepare the environment', 'info') # from this point we are sure we don't have to be careful # with local files/devices/disks/etc dst = "/etc/redis/redis.conf" redis = "{0}/etc/redis/{1}.conf".format(path, persistence) cron = "{0}/cron.d/{1}.cron".format(path, persistence) # redis will start with this conf log('configuring redis', 'info') os.system("/bin/cp -f {0} {1}".format(redis, dst)) if maxmemory > 0: os.system("/bin/sed 's/^# maxmemory <bytes>.*$/maxmemory {0}/' -i {1}".format(maxmemory, dst)) if policy != None: os.system("/bin/sed 's/^# maxmemory-policy.*$/maxmemory-policy {0}/' -i {1}".format(policy, dst)) # and root's cron will be set accordingly as well log('setting up cron', 'info') os.system("/bin/sed 's:INSTALLPATH:{0}:' {1} | /usr/bin/crontab".format(path, cron)) # ok, ready to set up assets like bucket and volume # also, if we have a valid mount, we don't do anything log('set up persistence', 'info') if os.path.ismount(mount) == False and "no" != persistence: log('create bucket {0}'.format(cluster), 'info') backup.create_bucket(key, access, cluster) try: # only try to create one if we have one if "" == snapshot or None == snapshot: raise Exception('metadata','empty snapshot') else: create_device(snapshot) except: try: latest = administration.get_latest_snapshot(key, access, cluster) create_device(latest) except: create_device() # we have a bucket, and perhaps a device. lets try to restore # from rdb, first from metadata later from user_data. if rdb != None and "" != rdb: log('restore rdb {0}/{1}'.format(cluster, rdb), 'info') backup.restore(key, access, cluster, rdb) latest = administration.get_latest_RDB(key, access, cluster) if "" != latest and None != latest: log('restore rdb {0}/{1}'.format(cluster, latest), 'info') backup.restore(key, access, cluster, latest)
set_cron() # are we a new cluster, or a clone from another? try: cluster = userdata['clone'] except: cluster = userdata['cluster'] # postgres is not running yet, so we have all the freedom we need #if userdata.has_key('tablespaces'): for tablespace in userdata['tablespaces']: # keep the size of main for later (WAL) if tablespace['name'] == "main": size_of_main = tablespace['size'] snapshot = administration.get_latest_snapshot(sys.argv[1], sys.argv[2], cluster, tablespace['name']) create_device(tablespace['device'], size=tablespace['size'], snapshot=snapshot) create_mount(tablespace['device'], tablespace['name']) add_monitor(tablespace['device'], tablespace['name']) # set the correct permissions, and some other necessities mount = pg_dir + "main" os.system("rm -rf {0}/*".format(mount)) os.system("chmod 0700 {0}".format(mount)) # prepare the new filesystem for postgres if not os.path.exists( "{0}/postgresql.conf".format(mount)): os.system("sudo -u postgres /usr/lib/postgresql/9.1/bin/pg_ctl -D {0} initdb".format(mount))
name = "{0}.{1}".format(name, hosted_zone) cluster = userdata['cluster'].strip() def snapshot_all(expiration="weekly"): # don't snapshot the WAL or root volume for tablespace in userdata['tablespaces']: backup = make_snapshot(sys.argv[2], sys.argv[3], cluster, tablespace['name'], expiration=expiration, device=tablespace['device']) administration.add_snapshot(sys.argv[2], sys.argv[3], cluster, tablespace['name'], backup) print "created {0} from {1}".format(backup[0], tablespace['name']) if "latest" == sys.argv[1]: print administration.get_latest_snapshot(sys.argv[2], sys.argv[3], cluster, sys.argv[4]) elif "basebackup" == sys.argv[1]: if not is_in_recovery(): start_backup(sys.argv[4]) snapshot_all() stop_backup() elif "snapshot" == sys.argv[1]: backup = make_snapshot(sys.argv[2], sys.argv[3], cluster, sys.argv[4], sys.argv[5]) administration.add_snapshot(sys.argv[2], sys.argv[3], cluster, sys.argv[4], backup) elif "snapshot-all" == sys.argv[1]: snapshot_all() elif "purge" == sys.argv[1]: snapshots = administration.get_expired_snapshots(sys.argv[2], sys.argv[3], name)
def snapshot_all(expiration="weekly"): # don't snapshot the WAL or root volume for tablespace in userdata['tablespaces']: backup = make_snapshot(sys.argv[2], sys.argv[3], cluster, tablespace['name'], expiration=expiration, device=tablespace['device']) administration.add_snapshot(sys.argv[2], sys.argv[3], cluster, tablespace['name'], backup) print "created {0} from {1}".format(backup[0], tablespace['name']) if "latest" == sys.argv[1]: print administration.get_latest_snapshot(sys.argv[2], sys.argv[3], cluster, sys.argv[4]) elif "basebackup" == sys.argv[1]: if not is_in_recovery(): start_backup(sys.argv[4]) snapshot_all() stop_backup() elif "snapshot" == sys.argv[1]: backup = make_snapshot(sys.argv[2], sys.argv[3], cluster, sys.argv[4], sys.argv[5]) administration.add_snapshot(sys.argv[2], sys.argv[3], cluster, sys.argv[4], backup) elif "snapshot-all" == sys.argv[1]: snapshot_all() elif "purge" == sys.argv[1]: snapshots = administration.get_expired_snapshots( sys.argv[2], sys.argv[3], name)
set_cron() # are we a new cluster, or a clone from another? try: cluster = userdata['clone'] except: cluster = userdata['cluster'] # postgres is not running yet, so we have all the freedom we need #if userdata.has_key('tablespaces'): for tablespace in userdata['tablespaces']: # keep the size of main for later (WAL) if tablespace['name'] == "main": size_of_main = tablespace['size'] snapshot = administration.get_latest_snapshot( sys.argv[1], sys.argv[2], cluster, tablespace['name']) create_device(tablespace['device'], size=tablespace['size'], snapshot=snapshot) create_mount(tablespace['device'], tablespace['name']) add_monitor(tablespace['device'], tablespace['name']) # set the correct permissions, and some other necessities mount = pg_dir + "main" os.system("rm -rf {0}/*".format(mount)) os.system("chmod 0700 {0}".format(mount)) # prepare the new filesystem for postgres if not os.path.exists("{0}/postgresql.conf".format(mount)):