Sync the latest archive to the host on given location.

        CLI Example:

        .. code-block:: bash

            salt '*' support.sync group=test
            salt '*' support.sync group=test name=/tmp/myspecial-12345-67890.bz2
            salt '*' support.sync group=test name=/tmp/myspecial-12345-67890.bz2 host=allmystuff.lan
            salt '*' support.sync group=test name=/tmp/myspecial-12345-67890.bz2 host=allmystuff.lan location=/opt/

        :param group: name of the local directory to which sync is going to put the result files
        :param name: name of the archive. Latest, if not specified.
        :param host: name of the destination host for rsync. Default is master, if not specified.
        :param location: local destination directory, default temporary if not specified
        :param move: move archive file[s]. Default is False.
        :param all: work with all available archives. Default is False (i.e. latest available)

        :return:

def sync(self, group, name=None, host=None, location=None, move=False, all=False):
        '''
        Sync the latest archive to the host on given location.

        CLI Example:

        .. code-block:: bash

            salt '*' support.sync group=test
            salt '*' support.sync group=test name=/tmp/myspecial-12345-67890.bz2
            salt '*' support.sync group=test name=/tmp/myspecial-12345-67890.bz2 host=allmystuff.lan
            salt '*' support.sync group=test name=/tmp/myspecial-12345-67890.bz2 host=allmystuff.lan location=/opt/

        :param group: name of the local directory to which sync is going to put the result files
        :param name: name of the archive. Latest, if not specified.
        :param host: name of the destination host for rsync. Default is master, if not specified.
        :param location: local destination directory, default temporary if not specified
        :param move: move archive file[s]. Default is False.
        :param all: work with all available archives. Default is False (i.e. latest available)

        :return:
        '''
        tfh, tfn = tempfile.mkstemp()
        processed_archives = []
        src_uri = uri = None

        last_arc = self.last_archive()
        if name:
            archives = [name]
        elif all:
            archives = self.archives()
        elif last_arc:
            archives = [last_arc]
        else:
            archives = []

        for name in archives:
            err = None
            if not name:
                err = 'No support archive has been defined.'
            elif not os.path.exists(name):
                err = 'Support archive "{}" was not found'.format(name)
            if err is not None:
                log.error(err)
                raise salt.exceptions.SaltInvocationError(err)

            if not uri:
                src_uri = os.path.dirname(name)
                uri = '{host}:{loc}'.format(host=host or __opts__['master'],
                                            loc=os.path.join(location or tempfile.gettempdir(), group))

            os.write(tfh, salt.utils.stringutils.to_bytes(os.path.basename(name)))
            os.write(tfh, salt.utils.stringutils.to_bytes(os.linesep))
            processed_archives.append(name)
            log.debug('Syncing %s to %s', name, uri)
        os.close(tfh)

        if not processed_archives:
            raise salt.exceptions.SaltInvocationError('No archives found to transfer.')

        ret = __salt__['rsync.rsync'](src=src_uri, dst=uri, additional_opts=['--stats', '--files-from={}'.format(tfn)])
        ret['files'] = {}
        for name in processed_archives:
            if move:
                salt.utils.dictupdate.update(ret, self.delete_archives(name))
                log.debug('Deleting %s', name)
                ret['files'][name] = 'moved'
            else:
                ret['files'][name] = 'copied'

        try:
            os.unlink(tfn)
        except (OSError, IOError) as err:
            log.error('Cannot remove temporary rsync file %s: %s', tfn, err)

        return self.format_sync_stats(ret)