Advertisement
Guest User

Untitled

a guest
Sep 29th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. #!py
  2.  
  3. # Import python libs
  4. from datetime import datetime
  5.  
  6. # Run function calls when the state is applied to a minion
  7. def run():
  8.   # Set up useful aliases
  9.   proj = pillar['project']
  10.  
  11.   state = {}
  12.   # Ensure that the backup dir exists
  13.   state['Backup dir'] = {
  14.           'file.directory': [
  15.                 {'name': proj['backup_dir']},
  16.                 {'user': proj['user']},
  17.                 ]
  18.             }
  19.   # Strip off seconds and microseconds
  20.   # from '2013-09-20 18:02:16.552374'
  21.   # to '2013.09.20-18:02:00'
  22.   today = str(datetime.now().replace( # datetime replace method
  23.             microsecond=0, second=0)).replace( # string replace method
  24.                     '-', '.').replace(' ', '-')
  25.   state['Make a backup .war file'] = {
  26.             'cmd.run': [
  27.                 {'name':
  28.                     'cp ROOT.war {0}/{1}'.format(proj['backup_dir'],
  29.                                                  today)},
  30.                 {'cwd':
  31.                     '{0}/hosts/MAIN'.format(proj['directory'])},
  32.                 {'user':
  33.                     proj['user']},
  34.                 {'require': [
  35.                     {'file': 'Backup dir'},
  36.                     ] },
  37.                ]
  38.         }
  39.   state['Delete old backups'] = {
  40.             'cmd.run': [
  41.                 {'name':
  42.                     ('find {0} -maxdepth 1 -mindepth 1 -type f '
  43.                      '-regex "{0}/.*" | sort -r | awk "NR > 5" | '
  44.                      'xargs rm -f').format(proj['backup_dir'])},
  45.                 {'require': [
  46.                      {'cmd': 'Make a backup .war file'},
  47.                     ] },
  48.                 ]
  49.         }
  50.   return state
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement