Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!py
- # Import python libs
- from datetime import datetime
- # Run function calls when the state is applied to a minion
- def run():
- # Set up useful aliases
- proj = pillar['project']
- state = {}
- # Ensure that the backup dir exists
- state['Backup dir'] = {
- 'file.directory': [
- {'name': proj['backup_dir']},
- {'user': proj['user']},
- ]
- }
- # Strip off seconds and microseconds
- # from '2013-09-20 18:02:16.552374'
- # to '2013.09.20-18:02:00'
- today = str(datetime.now().replace( # datetime replace method
- microsecond=0, second=0)).replace( # string replace method
- '-', '.').replace(' ', '-')
- state['Make a backup .war file'] = {
- 'cmd.run': [
- {'name':
- 'cp ROOT.war {0}/{1}'.format(proj['backup_dir'],
- today)},
- {'cwd':
- '{0}/hosts/MAIN'.format(proj['directory'])},
- {'user':
- proj['user']},
- {'require': [
- {'file': 'Backup dir'},
- ] },
- ]
- }
- state['Delete old backups'] = {
- 'cmd.run': [
- {'name':
- ('find {0} -maxdepth 1 -mindepth 1 -type f '
- '-regex "{0}/.*" | sort -r | awk "NR > 5" | '
- 'xargs rm -f').format(proj['backup_dir'])},
- {'require': [
- {'cmd': 'Make a backup .war file'},
- ] },
- ]
- }
- return state
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement