def replicate_per_farm_dbs(cloud_url=None, local_url=None, farm_name=None):
"""
Sete up replication of the per-farm databases from the local server to the
cloud server.
:param str cloud_url: Used to override the cloud url from the global
configuration in case the calling function is in the process of
initializing the cloud server
:param str local_url: Used to override the local url from the global
configuration in case the calling function is in the process of
initializing the local server
:param str farm_name: Used to override the farm name from the global
configuratino in case the calling function is in the process of
initializing the farm
"""
cloud_url = cloud_url or config["cloud_server"]["url"]
local_url = local_url or config["local_server"]["url"]
farm_name = farm_name or config["cloud_server"]["farm_name"]
username = config["cloud_server"]["username"]
password = config["cloud_server"]["password"]
# Add credentials to the cloud url
parsed_cloud_url = urlparse(cloud_url)
if not parsed_cloud_url.username:
new_netloc = "{}:{}@{}".format(
username, password, parsed_cloud_url.netloc
)
cloud_url = ParseResult(
parsed_cloud_url.scheme, new_netloc, parsed_cloud_url.path,
parsed_cloud_url.params, parsed_cloud_url.query,
parsed_cloud_url.fragment
).geturl()
server = Server(local_url)
for db_name in per_farm_dbs:
remote_db_name = "{}/{}/{}".format(username, farm_name, db_name)
server.replicate(
db_name, db_name, urljoin(cloud_url, remote_db_name),
continuous=True
)
评论列表
文章目录