Commits

Vladimir Mihailenco committed a114c46

Add timestamp to backup filename

  • Participants
  • Parent commits 67f5626

Comments (0)

Files changed (1)

File fab_deploy_ext/ssh.py

 import re
+import datetime
 
 from fabric.api import get
 from fabric.contrib.files import comment
     regex = '%s' % re.escape(key)
     regex = regex.replace('\/', '/')
 
+    now = datetime.datetime.now().strftime('%Y.%m.%d-%H.%M')
+    backup = '.%s.bak' % now
     for authorized_keys in ssh_list_files(users):
-        comment(authorized_keys, regex, use_sudo=use_sudo)
+        comment(authorized_keys, regex, use_sudo=use_sudo, backup=backup)
 
 
 def ssh_enable_key(key, users=None, use_sudo=False):
     regex = '%s' % re.escape(key)
 
+    now = datetime.datetime.now().strftime('%Y.%m.%d-%H.%M')
+    backup = '.%s.bak' % now
     for authorized_keys in ssh_list_files(users):
-        uncomment(authorized_keys, regex, use_sudo=use_sudo)
+        uncomment(authorized_keys, regex, use_sudo=use_sudo, backup=backup)