Postgresql – barman creating log files with incorrect owner

backupbarmanpostgresql

I've got the following config snippet in my /etc/barman.conf:

[barman]
; System user
barman_user = ubuntu

; Log location
log_file = /var/log/barman/barman.log

However, whenever the log file is rotated, this is what happens:

$ ls -l /var/log/barman/
total 860
-rw-r----- 1 barman adm         0 Dec  3 06:37 barman.log
-rw-rw-r-- 1 ubuntu ubuntu 875647 Dec  2 06:12 barman.log.1

And barman keeps throwing warnings/errors about this:

$ barman cron
2017-12-13 11:11:08,358 [11498] barman.utils WARNING: Failed opening the requested log file. Using standard error instead.

Is my barman config incorrect, is this a bug in barman, or is some OS/kernel-level security setting causing this behavior?

Edit: Owner of /var/log/barman

$ ls -ld /var/log/barman
drwxr-x--- 2 ubuntu ubuntu 4096 Dec  3 06:37 /var/log/barman

Edit: Output of barman diagnose

$ barman diagnose
2017-12-15 11:27:05,588 [3812] barman.utils WARNING: Failed opening the requested log file. Using standard error instead.
{
    "global": {
        "config": {
            "barman_home": "/home/ubuntu/barman", 
            "barman_user": "ubuntu", 
            "compression": "bzip2", 
            "configuration_files_directory": "/home/ubuntu/barman.conf.d", 
            "errors_list": [], 
            "last_backup_maximum_age": "2 WEEKS", 
            "log_file": "/var/log/barman/barman.log", 
            "log_level": "INFO", 
            "minimum_redundancy": "3", 
            "path_prefix": "/home/ubuntu/pg/bin", 
            "retention_policy": "RECOVERY WINDOW OF 4 WEEKS"
        }, 
        "system_info": {
            "barman_ver": "2.3", 
            "kernel_ver": "REDACTED", 
            "python_ver": "", 
            "release": "Distributor ID:\tUbuntu\nDescription:\tUbuntu 14.04.5 LTS\nRelease:\t14.04\nCodename:\ttrusty", 
            "rsync_ver": "rsync  version 3.1.0  protocol version 31", 
            "ssh_ver": ""
        }
    }, 
    "servers": {
        "pg": {
            "backups": {}, 
            "config": {
                "active": true, 
                "archiver": false, 
                "archiver_batch_size": 0, 
                "backup_directory": "/home/ubuntu/barman/pg", 
                "backup_method": "postgres", 
                "backup_options": "concurrent_backup", 
                "bandwidth_limit": null, 
                "barman_home": "/home/ubuntu/barman", 
                "barman_lock_directory": "/home/ubuntu/barman", 
                "basebackup_retry_sleep": 30, 
                "basebackup_retry_times": 0, 
                "basebackups_directory": "/home/ubuntu/barman/pg/base", 
                "check_timeout": 30, 
                "compression": "bzip2", 
                "conninfo": "host=REDACTED user=REDACTED dbname=REDACTED", 
                "custom_compression_filter": null, 
                "custom_decompression_filter": null, 
                "description": "pg DB", 
                "disabled": false, 
                "errors_directory": "/home/ubuntu/barman/pg/errors", 
                "immediate_checkpoint": false, 
                "incoming_wals_directory": "/home/ubuntu/barman/pg/incoming", 
                "last_backup_maximum_age": "14 days", 
                "max_incoming_wals_queue": null, 
                "minimum_redundancy": 3, 
                "msg_list": [], 
                "name": "pg", 
                "network_compression": false, 
                "parallel_jobs": 1, 
                "path_prefix": "/home/ubuntu/pg/bin", 
                "post_archive_retry_script": null, 
                "post_archive_script": null, 
                "post_backup_retry_script": null, 
                "post_backup_script": null, 
                "pre_archive_retry_script": null, 
                "pre_archive_script": null, 
                "pre_backup_retry_script": null, 
                "pre_backup_script": null, 
                "recovery_options": "", 
                "retention_policy": "window 4 w", 
                "retention_policy_mode": "auto", 
                "reuse_backup": null, 
                "slot_name": "pgbackup", 
                "ssh_command": null, 
                "streaming_archiver": true, 
                "streaming_archiver_batch_size": 0, 
                "streaming_archiver_name": "barman_receive_wal", 
                "streaming_backup_name": "barman_streaming_backup", 
                "streaming_conninfo": "host=REDACTED user=REDACTED dbname=REDACTED", 
                "streaming_wals_directory": "/home/ubuntu/barman/pg/streaming", 
                "tablespace_bandwidth_limit": null, 
                "wal_retention_policy": "simple-wal 4 w", 
                "wals_directory": "/home/ubuntu/barman/pg/wals"
            }, 
            "status": {
                "config_file": "/etc/postgresql/9.4/main/postgresql.conf", 
                "connection_error": null, 
                "current_size": 6165378560.0, 
                "current_xlog": "000000010000005A0000000D", 
                "data_directory": "/var/lib/postgresql/9.4/main", 
                "hba_file": "/etc/postgresql/9.4/main/pg_hba.conf", 
                "ident_file": "/etc/postgresql/9.4/main/pg_ident.conf", 
                "is_in_recovery": false, 
                "is_superuser": true, 
                "pg_basebackup_bwlimit": true, 
                "pg_basebackup_compatible": true, 
                "pg_basebackup_installed": true, 
                "pg_basebackup_path": "/home/ubuntu/pg/bin/pg_basebackup", 
                "pg_basebackup_tbls_mapping": true, 
                "pg_basebackup_version": "9.4.0", 
                "pg_receivexlog_compatible": true, 
                "pg_receivexlog_installed": true, 
                "pg_receivexlog_path": "/home/ubuntu/pg/bin/pg_receivexlog", 
                "pg_receivexlog_supports_slots": true, 
                "pg_receivexlog_synchronous": false, 
                "pg_receivexlog_version": "9.4.0", 
                "pgespresso_installed": false, 
                "replication_slot": [
                    "pgbackup", 
                    true, 
                    "5A/D000000"
                ], 
                "replication_slot_support": true, 
                "server_txt_version": "9.4.4", 
                "streaming": true, 
                "streaming_supported": true, 
                "synchronous_standby_names": [
                    ""
                ], 
                "systemid": "6202911203760332717", 
                "timeline": 1, 
                "wal_level": "hot_standby", 
                "xlogpos": "5A/D4E6CA8"
            }, 
            "wals": {
                "last_archived_wal_per_timeline": {
                    "00000001": {
                        "compression": "bzip2", 
                        "name": "000000010000005A0000000C", 
                        "size": 1679, 
                        "time": 1513163133.925488
                    }
                }
            }
        }
    }
}
2017-12-15 11:27:07,611 [3812] barman.diagnose INFO: {
    "global": {
        "config": {
            "barman_home": "/home/ubuntu/barman", 
            "barman_user": "ubuntu", 
            "compression": "bzip2", 
            "configuration_files_directory": "/home/ubuntu/barman.conf.d", 
            "errors_list": [], 
            "last_backup_maximum_age": "2 WEEKS", 
            "log_file": "/var/log/barman/barman.log", 
            "log_level": "INFO", 
            "minimum_redundancy": "3", 
            "path_prefix": "/home/ubuntu/pg/bin", 
            "retention_policy": "RECOVERY WINDOW OF 4 WEEKS"
        }, 
        "system_info": {
            "barman_ver": "2.3", 
            "kernel_ver": "REDACTED", 
            "python_ver": "", 
            "release": "Distributor ID:\tUbuntu\nDescription:\tUbuntu 14.04.5 LTS\nRelease:\t14.04\nCodename:\ttrusty", 
            "rsync_ver": "rsync  version 3.1.0  protocol version 31", 
            "ssh_ver": ""
        }
    }, 
    "servers": {
        "pg": {
            "backups": {}, 
            "config": {
                "active": true, 
                "archiver": false, 
                "archiver_batch_size": 0, 
                "backup_directory": "/home/ubuntu/barman/pg", 
                "backup_method": "postgres", 
                "backup_options": "concurrent_backup", 
                "bandwidth_limit": null, 
                "barman_home": "/home/ubuntu/barman", 
                "barman_lock_directory": "/home/ubuntu/barman", 
                "basebackup_retry_sleep": 30, 
                "basebackup_retry_times": 0, 
                "basebackups_directory": "/home/ubuntu/barman/pg/base", 
                "check_timeout": 30, 
                "compression": "bzip2", 
                "conninfo": "host=REDACTED user=REDACTED dbname=REDACTED", 
                "custom_compression_filter": null, 
                "custom_decompression_filter": null, 
                "description": "pg DB", 
                "disabled": false, 
                "errors_directory": "/home/ubuntu/barman/pg/errors", 
                "immediate_checkpoint": false, 
                "incoming_wals_directory": "/home/ubuntu/barman/pg/incoming", 
                "last_backup_maximum_age": "14 days", 
                "max_incoming_wals_queue": null, 
                "minimum_redundancy": 3, 
                "msg_list": [], 
                "name": "pg", 
                "network_compression": false, 
                "parallel_jobs": 1, 
                "path_prefix": "/home/ubuntu/pg/bin", 
                "post_archive_retry_script": null, 
                "post_archive_script": null, 
                "post_backup_retry_script": null, 
                "post_backup_script": null, 
                "pre_archive_retry_script": null, 
                "pre_archive_script": null, 
                "pre_backup_retry_script": null, 
                "pre_backup_script": null, 
                "recovery_options": "", 
                "retention_policy": "window 4 w", 
                "retention_policy_mode": "auto", 
                "reuse_backup": null, 
                "slot_name": "pgbackup", 
                "ssh_command": null, 
                "streaming_archiver": true, 
                "streaming_archiver_batch_size": 0, 
                "streaming_archiver_name": "barman_receive_wal", 
                "streaming_backup_name": "barman_streaming_backup", 
                "streaming_conninfo": "host=REDACTED user=REDACTED dbname=REDACTED", 
                "streaming_wals_directory": "/home/ubuntu/barman/pg/streaming", 
                "tablespace_bandwidth_limit": null, 
                "wal_retention_policy": "simple-wal 4 w", 
                "wals_directory": "/home/ubuntu/barman/pg/wals"
            }, 
            "status": {
                "config_file": "/etc/postgresql/9.4/main/postgresql.conf", 
                "connection_error": null, 
                "current_size": 6165378560.0, 
                "current_xlog": "000000010000005A0000000D", 
                "data_directory": "/var/lib/postgresql/9.4/main", 
                "hba_file": "/etc/postgresql/9.4/main/pg_hba.conf", 
                "ident_file": "/etc/postgresql/9.4/main/pg_ident.conf", 
                "is_in_recovery": false, 
                "is_superuser": true, 
                "pg_basebackup_bwlimit": true, 
                "pg_basebackup_compatible": true, 
                "pg_basebackup_installed": true, 
                "pg_basebackup_path": "/home/ubuntu/pg/bin/pg_basebackup", 
                "pg_basebackup_tbls_mapping": true, 
                "pg_basebackup_version": "9.4.0", 
                "pg_receivexlog_compatible": true, 
                "pg_receivexlog_installed": true, 
                "pg_receivexlog_path": "/home/ubuntu/pg/bin/pg_receivexlog", 
                "pg_receivexlog_supports_slots": true, 
                "pg_receivexlog_synchronous": false, 
                "pg_receivexlog_version": "9.4.0", 
                "pgespresso_installed": false, 
                "replication_slot": [
                    "pgbackup", 
                    true, 
                    "5A/D000000"
                ], 
                "replication_slot_support": true, 
                "server_txt_version": "9.4.4", 
                "streaming": true, 
                "streaming_supported": true, 
                "synchronous_standby_names": [
                    ""
                ], 
                "systemid": "6202911203760332717", 
                "timeline": 1, 
                "wal_level": "hot_standby", 
                "xlogpos": "5A/D4E6CA8"
            }, 
            "wals": {
                "last_archived_wal_per_timeline": {
                    "00000001": {
                        "compression": "bzip2", 
                        "name": "000000010000005A0000000C", 
                        "size": 1679, 
                        "time": 1513163133.925488
                    }
                }
            }
        }
    }
}

Best Answer

Looks like you have an /etc/logrotate.d/barman file that needs editing. Look for that, change the line create 0640 barman adm to create 0640 ubuntu ubuntu and that should fix this issue for you.