print 'Missing requests library needed by flowdock ... silenty ignoring'
        return

    f = facter.Facter()
    username = f.lookup('cfn_stack_name').replace('-', ' '),

    msg = 'Started Elasticsearch restore of snapshot "%s" (from "%s") into stack "%s"\n' % (snapshot, prefix, f.lookup('cfn_stack_name'))
    msg = msg + 'You will not be able to connect to Elasticsearch for a little while while the restore is happening.'

    try:
        r = requests.post("https://api.flowdock.com/messages/chat/" + token, data={'content': msg, 'event': 'comment', 'external_user_name': username})
        if r.status_code != 200:
            print 'Problem while posting to flowdock. Verify the token'
    except e:
            print 'error while posting to flowdock ' + e.msg

if __name__ == '__main__':
    parser = get_parser("This script will restore a snapshot into ES running on localhost:9200 (by default)")
    parser.add_argument("--list", action="store_true", help="List snapshots ONLY")
    parser.add_argument("--slackurl", action="store", help="Slack URL to post to on success")
    parser.add_argument("--flowdock", action="store", help="Flowdock Token to post on success")
    parser.add_argument("--slackchan", action="store", default="#linux", help="Slack channel to post to on success")
    parser.add_argument("--wait", action="store_true", default=False, help="Wait until backup completes")

    options = parser.parse_args()

    if options.debug:
        logger.setLevel(logging.DEBUG)

    restore_snapshot(options)
    if options.indices:
        snapdef['indices'] = ','.join(options.indices)

    try:
        sh.create(repository=options.repository, snapshot=snapshot, body=json.dumps(snapdef), wait_for_completion=options.wait, request_timeout=7200)

        # Housekeeping - delete old snapshots
        snapshots = sh.get(repository=options.repository, snapshot="_all", request_timeout=120)['snapshots']
        num_snaps = len(snapshots)
        if num_snaps > options.keep:
            up_to = num_snaps - options.keep
            logger.info('TOTAL: %d - Will delete 1 -> %d' % (num_snaps, up_to + 1))
            for snap in snapshots[0:up_to]:
                sh.delete(repository=options.repository, snapshot=snap['snapshot'], request_timeout=3600)
                logger.info('Deleted snapshot %s' % snap['snapshot'])
    except exceptions.TransportError as e:
        pass

if __name__ == '__main__':
    parser = get_parser("This script will take a snapshot and upload to S3")
    parser.add_argument("--wait", action="store_true", default=True, help="Wait for the backup to complete")
    parser.add_argument("--keep", action="store", default=60, help="Number of Elasticsearch snapshots to keep in S3")

    options = parser.parse_args()

    if options.debug:
        logger.setLevel(logging.DEBUG)

    take_snapshot(options)
        num_snaps = len(snapshots)
        if num_snaps > options.keep:
            up_to = num_snaps - options.keep
            logger.info('TOTAL: %d - Will delete 1 -> %d' %
                        (num_snaps, up_to + 1))
            for snap in snapshots[0:up_to]:
                sh.delete(repository=options.repository,
                          snapshot=snap['snapshot'],
                          request_timeout=3600)
                logger.info('Deleted snapshot %s' % snap['snapshot'])
    except exceptions.TransportError as e:
        pass


if __name__ == '__main__':
    parser = get_parser("This script will take a snapshot and upload to S3")
    parser.add_argument("--wait",
                        action="store_true",
                        default=True,
                        help="Wait for the backup to complete")
    parser.add_argument("--keep",
                        action="store",
                        default=60,
                        help="Number of Elasticsearch snapshots to keep in S3")

    options = parser.parse_args()

    if options.debug:
        logger.setLevel(logging.DEBUG)

    take_snapshot(options)
Exemple #4
0
    try:
        r = requests.post("https://api.flowdock.com/messages/chat/" + token,
                          data={
                              'content': msg,
                              'event': 'comment',
                              'external_user_name': username
                          })
        if r.status_code != 200:
            print 'Problem while posting to flowdock. Verify the token'
    except e:
        print 'error while posting to flowdock ' + e.msg


if __name__ == '__main__':
    parser = get_parser(
        "This script will restore a snapshot into ES running on localhost:9200 (by default)"
    )
    parser.add_argument("--list",
                        action="store_true",
                        help="List snapshots ONLY")
    parser.add_argument("--slackurl",
                        action="store",
                        help="Slack URL to post to on success")
    parser.add_argument("--flowdock",
                        action="store",
                        help="Flowdock Token to post on success")
    parser.add_argument("--slackchan",
                        action="store",
                        default="#linux",
                        help="Slack channel to post to on success")
    parser.add_argument("--wait",