How to activate dovecot plugin log delete mail

Hello,

Today I need to see in log file who delete mails.

First we activate plugins mail_log in dovecot
Edit: vim /etc/dovecot/conf.d/20-imap.conf

# Host allowed in URLAUTH URLs sent by client. "*" allows all.
#imap_urlauth_host =

protocol imap {
# Space separated list of plugins to load (default is global mail_plugins).
#mail_plugins = $mail_plugins
mail_plugins = $mail_plugins mail_log notify

# Maximum number of IMAP connections allowed for a user from each IP address.
# NOTE: The username is compared case-sensitively.
#mail_max_userip_connections = 10
mail_max_userip_connections = 100
}

And we add mail_plugins = $mail_plugins mail_log notify

Next we will edit : vim /etc/dovecot/conf.d/10-logging.conf

# mail_log plugin provides more event logging for mail processes.
plugin {
# Events to log. Also available: flag_change append
mail_log_events = delete undelete expunge copy mailbox_delete mailbox_rename
# Available fields: uid, box, msgid, from, subject, size, vsize, flags
# size and vsize are available only for expunge and copy events.
mail_log_fields = uid box msgid size
}

to show like this.

Last step restart dovecot.

systemctl restart dovecot

Check if you get any error, in log file you will see someting like this:

Nov 10 11:25:48 imap(user@domain.com): Info: delete: box=Deleted Messages, uid=1252, msgid=<008301d22aa0$53e164e0$fba42ea0$@futuracar
go.bg>, size=11817
Nov 10 11:25:48 imap(user@domain.com): Info: delete: box=Deleted Messages, uid=1253, msgid=<01fc01d22f6f$4b3c15f0$e1b441d0$@futuracar
go.bg>, size=11402
Nov 10 11:25:48 imap(user@domain.com): Info: delete: box=Deleted Messages, uid=1254, msgid=<01f201d23112$579c7750$06d565f0$@futuracar
go.bg>, size=11396

We make this change in Centos 7.2

Config Centos 6 with Postfix, Amavis-new, ClamAV And Spamassassin

Setup for Centos 6.

Step 1:  Install and activate Epel-release

yum install epel-release
vim /etc/yum.repos.d/epel.repo

and change this

[epel]
name=Extra Packages for Enterprise Linux 6 – $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

like this

[epel]
name=Extra Packages for Enterprise Linux 6 – $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

Step 2: Install amavisd-new, clamav and spamassassin:

yum install amavisd-new clamav clamav-devel clamd spamassassin

Verify amavis and clam user’s:

[root@server ~]# cat /etc/passwd | grep “amavis\|clamav”
clam:x:495:491:Clam Anti Virus Checker:/var/lib/clamav:/sbin/nologin
amavis:x:494:490:User for amavisd-new:/var/spool/amavisd:/sbin/nologin

Manually add clam to the amavis group:

[root@server ~]# gpasswd -a clam amavis
Adding user clam to group amavis

and now results
[root@server ~]# groups clam
clam : clam amavis

Finally, new services should have been added to the system:

[root@server ~]# chkconfig –list | grep “amavisd\|clamd\|spamassassin”
amavisd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
clamd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
clamd.amavisd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
spamassassin 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@server ~]# chkconfig amavisd on
[root@server ~]# chkconfig clamd on
[root@server ~]# chkconfig clamd.amavisd on

Step 3: Setup Services

vim /etc/clamd.conf

# Comment out the TCPSocket setting:
# TCPSocket 3310             <—–  (Disable this line)

Run comand freshclam

vim /etc/amavisd/amavisd.conf

edit line 20 with your domain
$mydomain = ‘ceae.info’; # a convenient default for other settings

edit line 152 with your fully-qualified domain name
$myhostname = ‘mail.ceae.info’; # must be a fully-qualified domain name!

service amavisd start
service clamd start
service clamd.amavisd start
service spamassassin start

Step 4: Integrate Amavis-new with Postfix.

Amavisd will pass all incoming mail to our antivirus and antispam and verify that we are receiving a clean mail, but at this moment we have postfix and amavisd isolated, we need make a small integration.

vim /etc/postfix/main.cf

append these lines at the end

content_filter=smtp-amavis:[127.0.0.1]:10024

edit next file

vim /etc/postfix/master.cf

append these lines at the end

smtp-amavis unix -      -       n       -            smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n  -       n      -        -       smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000

In line smtp-avavis unix – – n – <number> smtp
try that number value be the same that amavisd children

[root@server ~]# grep max_servers /etc/amavisd/amavisd.conf
$max_servers = 2; # num of pre-forked children (2..30 is common), -m

Vim, How to substitute tab with comma

Q: How to substitute tab with comma with vim ?

We have a file like that
q test
2 sdd
3 netst
4 sdfd
5 nestde
6 mailqre
7 netsta
8 whatr
9 masterq
10 majsd
11 rest
12 mssdjswd
13 uwefsdc
14 jurtewq
…….

I will use substitute command to change every occurrence in the whole file.
:%s/\t/,/g

Rezult:

q,test
2,sdd
3,netst
4,sdfd
5,nestde
6,mailqre
7,netsta
8,whatr
9,masterq
10,majsd
11,rest
12,mssdjswd
13,uwefsdc
14,jurtewq

Configure mail server on Centos 7 with Postfix, Dovecot, Apache, postfixadmin and Roundcube.

We starting from Centos 7 Infrastructure Server with Mail Server from Installer.
We have now:

1 – We have public IP
2 – Revers DNS for this IP
3 – Domain already bought.

Step 0. Preparing with minimal aplication to install:

yum -y install wget whois nc vim gpm ppp rp-pppoe dialog logwatch telnet nmap mutt
yum -y install epel-release
yum -y update
yum -y install perl-MailTools perl-MIME-EncWords perl-Email-Valid perl-Test-Pod dovecot dovecot-mysql  dovecot-pigeonhole  perl-Mail-Sender perl-Log-Log4perl imapsync offlineimap amavisd-new clamav perl-Razor-Agent mariadb-server opendkim vim wget crypto-utils mod_ssl.x86_64 php php-mysql php-fpm  clamav-update php-imap.x86_64 NetworkManager-tui mailx lrzip lzop lz4 arj  unzoo cabextract p7zip fail2ban php-mcrypt.x86_64
systemctl stop rpcbind
systemctl disable rpcbind

Step 1.  Setup your hostname server.
hostnamectl set-hostname mail.your-domain.tk
Edit you /etc/hosts to look like this
[root@mail ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.47 mail.your-domain.com mail

Step 2.  Test postfix local delivery
We create 2 users for local delivery test.
useradd -d /home/john -M -N -s /sbin/nologin john
useradd -d /home/mark -M -N -s /sbin/nologin mark

Now we will send a local mail.
echo Hello | mail -s test john@localhost
and will check if mail has been delivered
tail -f /var/log/maillog
Oct 21 14:55:58 localhost postfix/local[2916]: 770201440486: to=<john@localhost.your-domain.com>, orig_to=<john@localhost>, relay=local, delay=0.19, delays=0.13/0.02/0/0.04, dsn=2.0.0, status=sent (delivered to mailbox)

if works go to next step

Step 3. Setup MariaDB.
Config next /etc/my.cnf.d/server.cnf file like this:
# this is read by the standalone daemon and embedded servers
[server]
innodb_file_per_table
innodb_file_format = Barracuda
# this is only for the mysqld standalone daemon
[mysqld]

Enable mariadb service
systemctl enable mariadb.service
Start mariadb database server
systemctl start mariadb.service
Secure mariadb installation
mysql_secure_installation

Step 4. Configure Clam Antivirus

We need to configure how clam refreshes his database
vim /etc/sysconfig/freshclam

comment or remove last line
#  FRESHCLAM_DELAY=disabled-warn    # REMOVE ME

we will make a edit clamav config file
vim /etc/freshclam.conf

comment or remove line with words   “example”.

and finally update your viruses database.
freshclam

Step 5. Configure basic settings in spamassasin

Enable spamassasin service

systemctl start spamassassin.service
systemctl status spamassassin.service
systemctl enable spamassassin.service
update spamassasin definitions
sa-update
 Step 6. Integrate spamassasin and clamav with amavisd.
First install some app:
yum -y install clamav clamav-devel clamav-server clamd
We need to provide some config files.
cp /usr/share/doc/clamav-server-0.99.2/clamd.sysconfig /etc/sysconfig/clamd.amavisd
We need to adapt config file to our actual configuration.
vim /etc/sysconfig/clamd.amavisd

and add to last line

CLAMD_CONFIGFILE=/etc/clamd.d/amavisd.conf
CLAMD_SOCKET=/var/run/clamd.amavisd/clamd.sock
We will create a couple of new files
vim /etc/tmpfiles.d/clamd.amavisd.conf
add this content
d /var/run/clamd.amavisd 0755 amavis amavis -
Edit next file
vim /usr/lib/systemd/system/clamd@.service
with this content
[Unit]
Description = clamd scanner (%i) daemon
After = syslog.target nss-lookup.target network.target
[Service]
Type = simple
ExecStart = /usr/sbin/clamd -c /etc/clamd.d/%i.conf --foreground=yes
Restart = on-failure
PrivateTmp = true
[Install]
WantedBy=multi-user.target
Now we can enable clamd@amavisd service
systemctl start clamd@amavisd
systemctl enable clamd@amavisd
systemctl status clamd@amavisd
Configure amavisd service
vim /etc/amavisd/amavisd.conf
At line 16 set number of amavisd childrens.
More childres uses more ram but delivers more mail at once, one amavisd children consumes near 30% of cpu in a low end server, be careful if you receive a lot of mails at once can be a big punch in your cpu have too many childrens.
$max_servers = <number>
line 20 set $mydomain
$mydomain = ‘ceae.info’;
line 152 aprox set your hostname
$myhostname= ‘mail.ceae.info’;
Start service Amavisd
systemctl start amavisd.service
Enable service
systemctl enable amavisd.service
Step 7. Enable Apache and minim config.
yum -y install php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy curl curl-devel perl-libwww-perl ImageMagick libxml2 libxml2-devel mod_fcgid php-cli httpd-devel spamassassin unzip bzip2 unrar perl-DBD-mysql
systemctl start httpd.service
systemctl enable httpd.service
Edit config file
vim /etc/httpd/conf/httpd.conf
at line 86 edit with your admin email
# ServerAdmin root@localhost
at line 152 should be
## AllowOverride None
AllowOverride All
Config php
vim /etc/php.ini
at line 763 edit like this
;cgi.fix_pathinfo=1
cgi.fix_pathinfo=0
at line 877 edit like this
;date.timezone =
date.timezone = Europe/Berlin
And now restart apache
systemctl restart httpd.service
Step 8. Setup Postfixadmin
Download Postxiadmin
wget http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-3.0/postfixadmin-3.0.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fpostfixadmin%2Ffiles%2Fpostfixadmin%2Fpostfixadmin-3.0%2F&ts=1479731076&use_mirror=netix
 Move file to tar.gz file
mv postfixadmin-3.0.tar.gz\?r\=https\:%2F%2Fsourceforge.net%2Fprojects%2Fpostfixadmin%2Ffiles%2Fpostfixadmin%2Fpostfixadmin-3.0%2F postfixadmin-3.0.tar.gz
Extract folder
tar -zxvf postfixadmin-3.0.tar.gz -C /var/www/html/
cd /var/www/html/
chown -R root.apache postfixadmin-3.0/
 ln -s postfixadmin-3.0/ postfixadmin
We need to create postfix user database:
mysql -u root -p
MariaDB [(none)]> create database postfix;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT all on postfix.* to 'postfix'@'localhost' identified by 'yourPASSword';
Query OK, 0 rows affected (0.00 sec)
Now we have database, edit config file:
vim /var/www/html/postfixadmin/config.inc.php
$CONF[‘configured’] = true;
$CONF[‘setup_password’] = ‘YOUR-STRONG-PASSWORD’;
$CONF[‘database_type’] = ‘mysqli’;
$CONF[‘database_host’] = ‘localhost’;
$CONF[‘database_user’] = ‘postfix’;
$CONF[‘database_password’] = ‘yourPASSword’;
$CONF[‘database_name’] = ‘postfix’;
$CONF[‘show_password’] = ‘YES’;
$CONF[‘page_size’] = ’30’;
$CONF[‘default_aliases’] = array (
‘abuse’ => ‘abuse@ceae.info’,
‘hostmaster’ => ‘hostmaster@ceae.info’,
‘postmaster’ => ‘postmaster@ceae.info’,
‘webmaster’ => ‘webmaster@ceae.info’
);
$CONF[‘domain_path’] = ‘NO’;
$CONF[‘domain_in_mailbox’] = ‘YES’;
$CONF[‘maildir_name_hook’] = ‘NO’;
$CONF[‘transport’] = ‘YES’;
$CONF[‘vacation’] = ‘YES’;
$CONF[‘vacation_domain’] = ‘autoreply.ceae.info’;
$CONF[‘vacation_control’] =’YES’;
If your domain do not exist, activate this
$CONF['emailcheck_resolve_domain']='NO';
Now got to browser and type http://your-ip/postfixadmin/setup.php and setup your admin password.
Setup Postfixadmin Now login and create new domain and email http://YOUR-IP-server/postfixadmin/login.php
Step 10   Setup Dovecot.
Now we enable IMAP and POP3 service.
vim /etc/dovecot/dovecot-sql.conf.ext
# The mysqld.sock socket may be in different locations in different systems
driver = mysql
##
connect = host=localhost dbname=postfix user=postfix password=yourpassword
#
# Default password scheme.
# depends on your $CONF['encrypt'] setting:
# md5crypt  -> MD5-CRYPT
# md5       -> PLAIN-MD5
# cleartext -> PLAIN
default_pass_scheme = MD5-CRYPT
# Query to retrieve password. user can be used to retrieve username in other
# # formats also.
password_query = SELECT username AS user,password FROM mailbox WHERE username = '%u' AND active='1'
# Query to retrieve user information.
## user_query = SELECT maildir, 1001 AS uid, 1001 AS gid FROM mailbox WHERE username = '%u' AND active='1'
user_query = SELECT CONCAT('/var/spool/vmail/', domain,'/', maildir) AS home, CONCAT('maildir:/var/spool/vmail/',domain,'/', maildir) AS mail, 5000 AS uid, 12 AS gid, concat('dict:storage=',CAST(ROUND(quota / 1024) AS CHAR), '::proxy::quota') AS quota, CONCAT('*:storage=',CAST(quota AS CHAR), 'B') AS quota_rule FROM mailbox WHERE username = '%u' AND active = '1'
Now we edit next file:
vim /etc/dovecot/conf.d/dovecot-mysql-quota.conf.ext
connect = host=localhost dbname=postfix user=postfix password=yourpassword
map {
  pattern = priv/quota/storage
  table = quota2
  username_field = username
  value_field = bytes
}
map {
  pattern = priv/quota/messages
  table = quota2
  username_field = username
  value_field = messages
}
vim /etc/dovecot/dovecot.conf
line 24 tells dovecot what protocols  should serve
protocols = imap pop3
line 31 is what interfaces where dovecot will be listening
listen = *, ::
line 44 welcome message,
#login_greeting = Dovecot ready.
login_greeting = Server OK.
line 69 defines behavior when reboot dovecot service
shutdown_clients = yes
Edit custom logging
vim /etc/dovecot/conf.d/10-logging.conf
line 8 log file
log_path = /var/log/dovecot.log
line 32 logging verbose password for debuging
#auth_verbose_passwords = no
auth_verbose_passwords = plain
line 41 enable debug password
#auth_debug_passwords = no
auth_debug_passwords = yes
Restart dovecot
systemctl restart dovecot.service
Create user for delivery internal and log.
useradd -r -u 5000 -g mail -d /var/spool/vmail -s /sbin/nologin -c "Virtual mailbox" vmail
Create folder vmail
mkdir /var/spool/vmail
change owner of log file
chown vmail /var/log/dovecot.log
Create logrotate for dovecot
vim /etc/logrotate.d/dovecot
/var/log/dovecot.log {
missingok
notifempty
delaycompress
sharedscripts
postrotate
/bin/kill -USR1 `cat /var/run/dovecot/master.pid 2>/dev/null` 2> /dev/null || true
endscript
}
Config authenticated user
vim /etc/dovecot/conf.d/10-auth.conf
line 10 disable plain test on
disable_plaintext_auth = yes
Auth mecanism
auth_mechanisms = plain login cram-md5
and databate type user setup
#!include auth-system.conf.ext
!include auth-sql.conf.ext
Setup SSL
SSL protocols
ssl_protocols = !SSLv2 !SSLv3
SSL ciphers to use
ssl_cipher_list = EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+RC4:EECDH:EDH+aRSA:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4
Prefer the server’s order of ciphers over client’s.
ssl_prefer_server_ciphers = yes
 Now dovecot needs to know what protocols will  serve and how
vim /etc/dovecot/conf.d/10-master.conf
service imap-login {
  inet_listener imap {
    port = 143
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
service pop3-login {
  inet_listener pop3 {
    port = 110
  }
  inet_listener pop3s {
    port = 995
    ssl = yes
  }
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = vmail
    group = mail
  }
Enable sieve in dovecot
vim /etc/dovecot/conf.d/15-lda.conf
protocol lda {
# Space separated list of plugins to load (default is global mail_plugins).
#mail_plugins = $mail_plugins
mail_plugins = $mail_plugins sieve
}
end for today
——–>>>>>>>>—————–>>>>>>>>>>>>>>>>

File underconstruction ……  please return back in few days.

How to setup mx record for subdomain?

Questions of the day ?

How to setup a MX domain for subdomeniu.domeniu.ro ?

We just now edit zone file /var/named/master/db.domeniuro

;
; db.domeniu.ro
;
$TTL 300

@ 1d IN SOA ns.biotree.tk. lucian.biotree.ro. (
2016090701 ;Serial
10800 ;Refresh after 3 hours
3600 ;Retry after 1 hour
1209600 ;Expire after 1 week
86400 ) ;Minimum TTL of 1 day

;———————–___ Name Servers ____—————————-

1d IN NS ns.biotree.tk.
1d IN NS ns2.biotree.tk.
1d IN MX 5 mail.domeniu.ro.
1d IN MX 10 smtp2.domeniu.ro.
1d IN TXT “v=spf1 a mx ptr -all”

;———————–___ Aliases___________—————————-

mail IN A 75.226.34.29
mail2 IN A 81.76.59.37

subdomeniu  IN  A  74.54.89.56

;———- MX Subdomeni —————-
subdomeniu IN MX 5 mail.domeniu.ro.
subdomeniu IN MX 20 smtp2.domeniu.ro.

 

How we test if we setup right MX ?

[root@mail7 ~]# host -t mx subdomeniu.domeniu.ro
subdomeniu.domeniu.ro mail is handled by 20 smtp2.domeniu.ro.
subdomeniu.domeniu.ro mail is handled by 5 mail.domeniu.ro.

DNS Server ISP Romania.

Salut,

Mai jos pun lista de servere DNS oferite de fiecare Internet Service Provider (ISP) din Romania:
Voi trece în dreptul fiecarui IP și ce Reverse DNS are fiecare. Daca nu are se trece none.

  1.  DNS Telekom
    193.231.100.2 – ns1.romtelecom.net
    193.231.100.3 – ns2.romtelecom.net
    193.231.100.130 – ns3.romtelecom.net
    193.231.100.134 – ns4.romtelecom.net
  2. DNS RDS
    193.231.236.25 – dns-cache-1.rdsnet.ro
    193.231.236.30 – dns-cache-2.rdsnet.ro
    193.231.236.17 –  ns1.rdsnet.ro
    193.231.236.10 –  ns2.rdsnet.ro
    213.154.124.1   –  dns1.rcs-rds.ro
    193.231.252.1   –  dns2.rcs-rds.ro
  3. DNS Vodafone
    81.12.128.206 – 81.12.128.206.vodafonenet.ro
    81.12.132.206 – 81.12.132.206.vodafonenet.ro
    193.230.161.3  –  none
    193.230.161.4  –  none
  4. DNS Orange
    62.217.193.1  –  ns1.orange.ro
    62.217.193.65  – ns2.orange.ro
    62.217.251.167  –  dedal.orange.ro
    62.217.251.162  –  walkiria.orange.ro
  5. DNS UPC, Astral
    95.77.94.77  –  nsc2.upcbiz.ro
    78.96.7.88   –  ro-cj01a-dns01.upcnet.ro
    95.77.94.88   –  ro-buh01a-dns01.upcnet.ro
    194.102.255.2  –  ns0.b.astral.ro
    194.102.255.3   – ns1.b.astral.ro
    193.230.240.21  – ns1.upcbiz.ro
    193.230.240.22  – ns2.upcbiz.ro
    194.102.255.26  – ns3.upcbiz.ro
    193.226.99.18  –   ns4.upcbiz.ro
  6. DNS INES
    80.86.96.1    –   NS-1.iNES.RO
    80.86.96.11  –   NS-2.iNES.RO
  7. DNS Nextgen
    188.173.1.21  –  188-173-1-21.next-gen.ro
    94.53.12.14    –  94-53-12-14.next-gen.ro
  8. DNS Primetelecom
    89.37.120.6  –  ns1.primetelecom.ro
    89.34.72.42  –  ns2.primetelecom.ro

 

DNS gratuit avem o lista scurta de Google și OpenDNS:

    1. Google
      8.8.8.8   –  google-public-dns-a.google.com
      8.8.4.4   –  google-public-dns-b.google.com
    2. OpenDNS
      208.67.222.222  –  resolver1.opendns.com
      208.67.220.220  – resolver2.opendns.com
    3. DNS gratuit de la freenom.com
      80.80.80.80    – no revers DNS
      80.80.81.81     – no revers DNS
    4. DNS gratuit de la IBM quad9
      9.9.9.9 – dns.quad9.net

UPDATE: 04.12.2017

Scopul acestei postari este doar personal și voi face update periodic.

How to Clone a PostgreSQL database!

At some point in development, you may want to make a copy of your existing development database to play with an unstable new feature. Postgres makes it super trivial to do that by allow us to create a new database by using existing database as a template.

In postgres console, run

=# CREATE DATABASE new_database_name WITH TEMPLATE original_database_name;

Boom!, you got a cloned database named new_database_name.

Credit: Creating a copy of a database in Postgres
I’ve seen a convenient way to make a clone across remote server too. (Haven’t try) How to copy postgres database to another server

Easy step.
Instead of running command in psql, we can use createdb with -T flag like so

$ createdb -T original_database_name new_database_name

Credit: http://stackoverflow.com/a/6739995

How to fix auto-read-only mdadm.

This guide shows you a simple way to fix your mdadm raid based drives which are not syncing or in the auto-read-only mode.

To find the names of your drives which are under auto-read-only mode or not syncing

cat /proc/mdstat

Force the drives to sync.

mdadm --readwrite /dev/md9

Replace md9 with the name of the drive like md127 etc.
server ~ # cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] [linear] [multipath]
md125 : active (auto-read-only) raid1 sda1[0] sdb1[1]
      192640 blocks [2/2] [UU]

md126 : active raid1 sda5[0] sdb5[1]
      97650944 blocks [2/2] [UU]
        resync=DELAYED

md127 : active raid1 sdb2[1] sda2[0]
      97659008 blocks [2/2] [UU]
      [=>...................]  resync =  8.8% (8686848/97659008) finish=64.0min speed=23148K/sec

md128 : active (auto-read-only) raid1 sdb6[1] sda6[0]
      288875200 blocks [2/2] [UU]

Source Info: http://wiki.crowncloud.net/doku.php/how_to_fix_auto-read-only_mdadm

CP: max source files number arguments for copy utility

Hello

Today we have a problem: We get this error when we try to copy over 32356 file in other folder.
[root@mail server-xv.ro]# cp -p office_23\@domain.ro/new/1* office\@domain.ro/.Inbox_2016_06_23/cur/
-bash: /bin/cp: Argument list too long

Solutions: run your command in a loop.

[root@mail server-xv.ro]# for file in office_23\@domain.ro/new/*; do cp -p “$file” office\@domain.ro/.Inbox_2016_06_23/cur/; done

And works very well.