Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup configuration files before overwriting #11216

Merged
merged 2 commits into from
Dec 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions homeassistant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,68 @@ def create_default_config(config_dir, detect_location=True):

config_file.write(DEFAULT_CONFIG)

timestamp = date_util.now().strftime('%Y%m%dT%H%M%S')
# Check for existing secrets file.
# If it exists, back it up before recreating it.
if os.path.isfile(secret_path):
backup_secret_path = "{}.{}.bak".format(
secret_path,
timestamp
)
print("Found existing secrets file. Backing up and re-creating.")
os.rename(secret_path, backup_secret_path)
with open(secret_path, 'wt') as secret_file:
secret_file.write(DEFAULT_SECRETS)

with open(version_path, 'wt') as version_file:
version_file.write(__version__)

# Check for existing group file.
# If it exists, back it up before recreating it.
if os.path.isfile(group_yaml_path):
backup_group_path = "{}.{}.bak".format(
group_yaml_path,
timestamp
)
print("Found existing group file. Backing up and re-creating.")
os.rename(group_yaml_path, backup_group_path)
with open(group_yaml_path, 'wt'):
pass

# Check for existing automation file.
# If it exists, back it up before recreating it.
if os.path.isfile(automation_yaml_path):
backup_automation_path = "{}.{}.bak".format(
automation_yaml_path,
timestamp
)
print("Found existing automation file. Backing up and",
"re-creating.")
os.rename(automation_yaml_path, backup_automation_path)
with open(automation_yaml_path, 'wt') as fil:
fil.write('[]')

# Check for existing group file.
# If it exists, back it up before recreating it.
if os.path.isfile(script_yaml_path):
backup_script_path = "{}.{}.bak".format(
script_yaml_path,
timestamp
)
print("Found existing script file. Backing up and re-creating.")
os.rename(script_yaml_path, backup_script_path)
with open(script_yaml_path, 'wt'):
pass

# Check for existing customize file.
# If it exists, back it up before recreating it.
if os.path.isfile(customize_yaml_path):
backup_customize_path = "{}.{}.bak".format(
customize_yaml_path,
timestamp
)
print("Found existing customize file. Backing up and re-creating.")
os.rename(customize_yaml_path, backup_customize_path)
with open(customize_yaml_path, 'wt'):
pass

Expand Down