{"action":"created","issue":{"url":"https://api.github.com/repos/andryyy/mailcow/issues/712","repository_url":"https://api.github.com/repos/andryyy/mailcow","labels_url":"https://api.github.com/repos/andryyy/mailcow/issues/712/labels{/name}","comments_url":"https://api.github.com/repos/andryyy/mailcow/issues/712/comments","events_url":"https://api.github.com/repos/andryyy/mailcow/issues/712/events","html_url":"https://github.com/andryyy/mailcow/issues/712","id":197906276,"number":712,"title":"Easy to use backup system","user":{"login":"MrCoala","id":18616998,"avatar_url":"https://avatars.githubusercontent.com/u/18616998?v=3","gravatar_id":"","url":"https://api.github.com/users/MrCoala","html_url":"https://github.com/MrCoala","followers_url":"https://api.github.com/users/MrCoala/followers","following_url":"https://api.github.com/users/MrCoala/following{/other_user}","gists_url":"https://api.github.com/users/MrCoala/gists{/gist_id}","starred_url":"https://api.github.com/users/MrCoala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrCoala/subscriptions","organizations_url":"https://api.github.com/users/MrCoala/orgs","repos_url":"https://api.github.com/users/MrCoala/repos","events_url":"https://api.github.com/users/MrCoala/events{/privacy}","received_events_url":"https://api.github.com/users/MrCoala/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-28T19:45:51Z","updated_at":"2016-12-29T23:58:56Z","closed_at":null,"body":"Mailcow should provide a utility to backup all important mailbox files and database entries into one archive file"},"comment":{"url":"https://api.github.com/repos/andryyy/mailcow/issues/comments/269712462","html_url":"https://github.com/andryyy/mailcow/issues/712#issuecomment-269712462","issue_url":"https://api.github.com/repos/andryyy/mailcow/issues/712","id":269712462,"user":{"login":"miclnl","id":11257729,"avatar_url":"https://avatars.githubusercontent.com/u/11257729?v=3","gravatar_id":"","url":"https://api.github.com/users/miclnl","html_url":"https://github.com/miclnl","followers_url":"https://api.github.com/users/miclnl/followers","following_url":"https://api.github.com/users/miclnl/following{/other_user}","gists_url":"https://api.github.com/users/miclnl/gists{/gist_id}","starred_url":"https://api.github.com/users/miclnl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miclnl/subscriptions","organizations_url":"https://api.github.com/users/miclnl/orgs","repos_url":"https://api.github.com/users/miclnl/repos","events_url":"https://api.github.com/users/miclnl/events{/privacy}","received_events_url":"https://api.github.com/users/miclnl/received_events","type":"User","site_admin":false},"created_at":"2016-12-29T23:58:56Z","updated_at":"2016-12-29T23:58:56Z","body":"I was working on a migration tool (0.14->docker) a while ago. It already does compressed backups of the e-mails and the databases, so I've removed the other functions for now.\r\n\r\n```\r\n#!/usr/bin/env bash\r\nfunction backup () {\r\n\tlocal configfile=$1\r\n\tlocal backuplocation=$2\r\n\tlocal compress=$3 || echo 1\r\n\tlocal tmpdir\r\n\tlocal currtime\r\n\t\r\n\tcurrtime=$(date \"+%m%d%H%M%S\")\r\n\ttmpdir=\"$(dirname \"$backuplocation\")/.tmp_mailcow_backup_${currtime}\"\r\n\t\r\n\tif [  -d \"$backuplocation\" ]; then\r\n\t\t# user gave dir, auto-generate filename\r\n\t\tbackuplocation=\"$(realpath \"$backuplocation\")/mailcow_backup_${currtime}\"\r\n\tfi\r\n\t#\r\n\t# Checking paths and permissions\r\n\t#\r\n\t\r\n\tlogoutput \"[*] Checking file permissions...\"\r\n\tif [[ ! -w  $(dirname \"$backuplocation\") ]]; then \r\n\t\tlogoutput \"\\tError: Cannot write ${backuplocation}, please check path and permissions\"\r\n\t\texit 1\r\n\tfi\r\n\tif [[ ! -r /var/mail/sogo ]]; then\r\n\t\tlogoutput \"\\tError: Cannot read /var/vmail, please check permissions\"\r\n\t\texit 1\r\n\tfi\r\n\tlogoutput \"\\tPermissions OK\"\r\n\t\r\n\t# read variables from the config file\r\n\tlogoutput \"[*] Reading config file: \"\r\n\treadconfigfile \"$configfile\"\r\n\t# $loginarray=(host name user pass)\r\n\t\r\n\tlogoutput \"\\tRead: ${loginarray[@]}\"\r\n\t\r\n\tif [ ${#loginarray[@]} -lt 3 ]; then \r\n\t\tlogoutput \"\\tError: Reading mailcow config file failed!\"\r\n\t\texit 1\r\n\tfi\r\n\t\r\n\t# Backup E-mails\r\n\tlogoutput \"[*] Backing up e-mails...\"\r\n\t\r\n\tmkdir -p \"$tmpdir\"\r\n\trsync -az --delete \"/var/vmail\" \"$tmpdir\" || { logoutput \"\\tError: Failed to copy files from /var/vmail!: $?\"; exit 1; }\r\n\tlogoutput \"\\tSuccessfully copied $(du -h -s \"$tmpdir\" | cut -f 1) of data.\"\r\n\r\n\r\n\t# Backup database\r\n\tlogoutput \"[*] Backing up databases...\"\r\n\t\r\n\tif [ ${#loginarray[@]} -lt 4 ]; then \r\n\t\t# No mysql pass required (or something went wrong otherwise)\r\n\t\tmysqldump --host \"${loginarray[0]}\" --user \"${loginarray[2]}\" \"${loginarray[1]}\" > ${tmpdir}/mailcow_database.sql\r\n\telse\r\n\t\tmysqldump --host \"${loginarray[0]}\" --user \"${loginarray[2]}\" --password=\"${loginarray[3]}\" \"${loginarray[1]}\" > ${tmpdir}/mailcow_database.sql\r\n\tfi\r\n\t\r\n\tif [ \"$?\" -ne 0 ]; then\r\n\t\tlogoutput \"\\tError: mysqldump failed: $?\"\r\n\t\tlogoutput \"\\tPartial backup still available at ${tmpdir}.\"\r\n\t\texit 1;\r\n\tfi\r\n\tlogoutput \"\\tSuccessfully dumped database.\"\r\n\r\n\t# Translate config file\r\n\tlogoutput \"[*] Translating config file...\"\r\n\tgenconf \"$configfile\" \"$tmpdir\"\r\n\r\n\tif [ \"$compress\" -eq \"1\" ]; then\r\n\t\tlogoutput \"[*] Packing and compressing backup (bzip2)...\"\r\n\t\ttar -cjSf \"$backuplocation\" \"$tmpdir\"\r\n\t\tif [[ \"$?\" -ne 0 ]]; then\r\n\t\t\tlogoutput \"\\tError: Packing and compressing failed: $?\"\r\n\t\t\tlogoutput \"\\tPartial backup still available at ${tmpdir}.\"\r\n\t\t\texit 1\r\n\t\telse\r\n\t\t\trm -Rf \"$tmpdir\"\r\n\t\t\tlogoutput \"\\tCompression succesfull.\"\r\n\t\t\tlogoutput \"\\tBACKUP SUCCES: Your backuplocation is located at ${backuplocation}\"\r\n\t\tfi\r\n\telse\r\n\t\tlogoutput \"BACKUP SUCCES:  Files located at ${tmpdir}\"\r\n\tfi\r\n\treturn 0\r\n\t\r\n}\r\nfunction restore () {\r\n\tlocal configfile=$1\r\n\tlocal backuplocation=$2\r\n\t\r\n\tlogoutput \"Restore not yet implemented\"\r\n\texit 1\r\n\t\r\n\t\r\n\tif [[ ! -r  \"$backuplocation\" ]]; then \r\n\t\tlogoutput \"Error: Cannot read ${backuplocation}, please check path and permissions\"\r\n\t\texit 1\r\n\tfi\r\n\t# TODO\r\n\t\r\n}\r\n\r\nfunction logoutput () {\r\n\techo -e \"$@\" | tee -a mailcow_backup.log\r\n}\r\n\r\nfunction checkconfigfile () {\r\n\tlocal configfile=$1\r\n\r\n\tif [[ ! -r  \"$configfile\" ]]; then \r\n\t\tlogoutput \"Error: Cannot read ${configfile}, please check path and permissions\"\r\n\t\texit 1\r\n\tfi\r\n\r\n\t[[ $(sed -nr 's/\\$database\\_type \\= \\\"([^\\\"]*)\\\";/\\1/p' \"$configfile\") == \"mysql\" ]] || { \r\n\t\tlogoutput \"Error: Your database is not mysql. This tools requires this.\"\r\n\t\texit 1\r\n\t}\r\n\t\t\r\n\treturn 0\r\n}\r\n\r\nfunction readconfigfile() {\r\n\tlocal configfile=$1\r\n\tdeclare -g loginarray=()\r\n\t\r\n\tloginarray[0]=\"$(sed -nr 's/\\$database\\_host \\= \\\"([^\\\"]*)\\\";/\\1/p' \"$configfile\")\"\r\n\tloginarray[1]=\"$(sed -nr 's/\\$database\\_name \\= \\\"([^\\\"]*)\\\";/\\1/p' \"$configfile\")\"\r\n\tloginarray[2]=\"$(sed -nr 's/\\$database\\_user \\= \\\"([^\\\"]*)\\\";/\\1/p' \"$configfile\")\"\r\n\tloginarray[3]=\"$(sed -nr 's/\\$database\\_pass \\= \\\"([^\\\"]*)\\\";/\\1/p' \"$configfile\")\"\r\n\t\r\n}\r\n\r\nfunction usage () {\r\n\techo \"mailcow backup tool\"\r\n\techo \"Usage: $0 <command> [-c <path>] [-b <path>]\"\r\n\techo\r\n\t\r\n\techo \"Valid commands:\"\r\n\techo -e \"backup\\t\\t\\tWill backup local non-docker setup of mailcow.\"\r\n#\techo -e \"restore\\t\\t\\tWill restore a previously made backup.\"\r\n\techo\r\n\t\r\n\techo \"Valid options:\"\r\n\techo -e \"-c <path>\\t\\tDefine location of mailcow directory (defaults /var/www/mail).\"\r\n\techo -e \"-b <path>\\t\\tDefine location of backup bzip2 archive.\"\r\n\techo\r\n\t\r\n\texit 0\r\n}\r\nfunction main () {\r\n\tlocal configfile\r\n\tlocal backuplocation\r\n\tlocal task\r\n\t\r\n\tif [[ \"$#\" -eq \"0\" ]] || [[ \"$1\" == *\"help\" ]]; then\r\n\t\tusage\r\n\tfi\r\n\r\n\tconfigfile=$(realpath \"/var/www/mail/inc/vars.inc.php\")\r\n\tbackuplocation=$(realpath \"./mailcow_migration_backup.tar.bz2\")\r\n\t\r\n\t# Parse args\r\n\ttask=$1; shift\r\n\r\n\twhile getopts :c:b: par \"$@\"; do\r\n\t\tcase \"$par\" in\r\n\t\t\tc|C) configfile=$OPTARG ;;\r\n\t\t\tb|B) backuplocation=$OPTARG ;;\r\n\t\tesac\r\n\tdone\r\n\t\r\n\tlogoutput \"STARTING mailcow migration ${task} on $(date)\"\r\n\tcheckconfigfile \"$configfile\"\r\n\t\r\n\tcase \"$task\" in\r\n\t\tbackup)\r\n\t\t\tbackup \"$configfile\" \"$backuplocation\" 1\r\n\t\t;;\r\n#\t\trestore)\r\n#\t\t\trestore \"$configfile\" \"$backuplocation\"\r\n#\t\t;;\r\n\t\t*) usage ;;\r\n\tesac\r\n\texit 0\r\n}\r\nmain \"$@\"\r\n```\r\n"}}
{"actor":{"display_login":"miclnl"}}