Esempio n. 1
0
def backup_db():
    if enabled and backup_path:
        accountsdir = "%s/%s_accounts" % (backup_path, datetime.date.today())
        worlddir = "%s/%s_world" % (backup_path, datetime.date.today())
        if accountsdriver == 'mysql' or worlddriver == 'mysql':
            try:
                # What are we optimizing
                if accountsdriver == 'mysql' and worlddriver == 'mysql':
                    log(
                        LOG_MESSAGE,
                        "Doing a backup for the accounts and world databases..."
                    )
                    if not os.path.isdir(accountsdir):
                        os.mkdir(accountsdir)
                    if not os.path.isdir(worlddir):
                        os.mkdir(worlddir)
                elif accountsdriver == 'mysql' or worlddriver == 'mysql':
                    if accountsdriver == 'mysql':
                        if not os.path.isdir(accountsdir):
                            os.mkdir(accountsdir)
                        log(LOG_MESSAGE,
                            "Doing a backup for the accounts database...")
                    elif worlddriver == 'mysql':
                        if not os.path.isdir(worlddir):
                            os.mkdir(worlddir)
                        log(LOG_MESSAGE,
                            "Doing a backup for the world database...")
                # Time to backup
                if accountsdriver == 'mysql':
                    database.open(database.ACCOUNTS)
                    database.execute("BACKUP TABLE %s TO '%s'" %
                                     (database.MYSQL_ACCOUNTS, accountsdir))
                    database.close()
                    log(LOG_MESSAGE,
                        "Accounts database saved to: %s" % (accountsdir))
                if worlddriver == 'mysql':
                    database.open(database.WORLD)
                    database.execute("BACKUP TABLE %s TO '%s'" %
                                     (database.MYSQL_WORLD, worlddir))
                    database.close()
                    #else:
                    #	log( LOG_MESSAGE, "Warning: Failed to open the world database!" )
                    log(LOG_MESSAGE,
                        "World database saved to: %s" % (worlddir))
            except:
                log(LOG_MESSAGE,
                    " Backup of the accounts/world database failed.")
        return True
    else:
        return False
Esempio n. 2
0
def onUpdateAcctDatabase(current, version):
	database.open(ACCOUNTS)

	driver = database.driver(ACCOUNTS)
	if driver == 'mysql':
		updates = ACCT_MYSQL_UPDATES
	elif driver == 'sqlite':
		updates = ACCT_SQLITE_UPDATES
	else:
		console.log(LOG_ERROR, "Unknown database driver for Accounts: %s.\n" % driver)
		database.close(ACCOUNTS)
		return False

	for i in range(version, current):
		# No update for this version available
		if not i in updates:
			console.log(LOG_ERROR, "No update available for database version %u.\n" % i)
			database.close(ACCOUNTS)
			return False

		console.log(LOG_MESSAGE, "Updating database from version %u to %u.\n" % (i, i+1))

		try:
			if not updates[i]():
				database.close(ACCOUNTS)
				return False
		except Exception, e:
			console.log(LOG_ERROR, str(e) + "\n")
			database.close(ACCOUNTS)
			return False

		# Updating Version Number
		updateacctversion(i+1, driver)
def backup_db():
	if enabled and backup_path:
		accountsdir = "%s/%s_accounts" % ( backup_path, datetime.date.today() )
		worlddir = "%s/%s_world" % ( backup_path, datetime.date.today() )
		if accountsdriver == 'mysql' or worlddriver == 'mysql':
			try:
				# What are we optimizing
				if accountsdriver == 'mysql' and worlddriver == 'mysql':
					log( LOG_MESSAGE, "Doing a backup for the accounts and world databases..." )
					if not os.path.isdir( accountsdir ):
						os.mkdirs( accountsdir )
						os.chmod( accountsdir, 0777)
					if not os.path.isdir( worlddir ):
						os.mkdirs( worlddir )
						os.chmod( worlddir, 0777)
				elif accountsdriver == 'mysql' or worlddriver == 'mysql':
					if accountsdriver == 'mysql':
						if not os.path.isdir( accountsdir ):
							os.mkdirs( accountsdir )
							os.chmod( accountsdir, 0777)
						log( LOG_MESSAGE, "Doing a backup for the accounts database..." )
					elif worlddriver == 'mysql':
						if not os.path.isdir( worlddir ):
							os.mkdirs( worlddir )
							os.chmod( worlddir, 0777)
						log( LOG_MESSAGE, "Doing a backup for the world database..." )
				# Time to backup
				if accountsdriver == 'mysql':
					database.open( database.ACCOUNTS )
					database.execute( "BACKUP TABLE %s TO '%s'" % ( database.MYSQL_ACCOUNTS, accountsdir ) )
					database.close()
					log( LOG_MESSAGE, "Accounts database saved to: %s" % ( accountsdir ) )
				if worlddriver == 'mysql':
					database.open( database.WORLD )
					database.execute( "BACKUP TABLE %s TO '%s'" % ( database.MYSQL_WORLD, worlddir ) )
					database.close()
					#else:
					#	log( LOG_MESSAGE, "Warning: Failed to open the world database!" )
					log( LOG_MESSAGE, "World database saved to: %s" % (worlddir ) )
			except:
				log( LOG_MESSAGE, " Backup of the accounts/world database failed." )
		return True
	else:
		return False
Esempio n. 4
0
def onUpdateAcctDatabase(current, version):
    database.open(ACCOUNTS)

    driver = database.driver(ACCOUNTS)
    if driver == 'mysql':
        updates = ACCT_MYSQL_UPDATES
    elif driver == 'sqlite':
        updates = ACCT_SQLITE_UPDATES
    else:
        console.log(LOG_ERROR,
                    "Unknown database driver for Accounts: %s.\n" % driver)
        database.close(ACCOUNTS)
        return False

    for i in range(version, current):
        # No update for this version available
        if not i in updates:
            console.log(LOG_ERROR,
                        "No update available for database version %u.\n" % i)
            database.close(ACCOUNTS)
            return False

        console.log(LOG_MESSAGE,
                    "Updating database from version %u to %u.\n" % (i, i + 1))

        try:
            if not updates[i]():
                database.close(ACCOUNTS)
                return False
        except Exception, e:
            console.log(LOG_ERROR, str(e) + "\n")
            database.close(ACCOUNTS)
            return False

        # Updating Version Number
        updateacctversion(i + 1, driver)
Esempio n. 5
0
                    "Unknown database driver for Accounts: %s.\n" % driver)
        database.close(ACCOUNTS)
        return False

    for i in range(version, current):
        # No update for this version available
        if not i in updates:
            console.log(LOG_ERROR,
                        "No update available for database version %u.\n" % i)
            database.close(ACCOUNTS)
            return False

        console.log(LOG_MESSAGE,
                    "Updating database from version %u to %u.\n" % (i, i + 1))

        try:
            if not updates[i]():
                database.close(ACCOUNTS)
                return False
        except Exception, e:
            console.log(LOG_ERROR, str(e) + "\n")
            database.close(ACCOUNTS)
            return False

        # Updating Version Number
        updateacctversion(i + 1, driver)

    database.close(ACCOUNTS)

    return True
Esempio n. 6
0
	else:
		console.log(LOG_ERROR, "Unknown database driver for Accounts: %s.\n" % driver)
		database.close(ACCOUNTS)
		return False

	for i in range(version, current):
		# No update for this version available
		if not i in updates:
			console.log(LOG_ERROR, "No update available for database version %u.\n" % i)
			database.close(ACCOUNTS)
			return False

		console.log(LOG_MESSAGE, "Updating database from version %u to %u.\n" % (i, i+1))

		try:
			if not updates[i]():
				database.close(ACCOUNTS)
				return False
		except Exception, e:
			console.log(LOG_ERROR, str(e) + "\n")
			database.close(ACCOUNTS)
			return False

		# Updating Version Number
		updateacctversion(i+1, driver)


	database.close(ACCOUNTS)

	return True