October 2025
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

October 2025
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Recover lost passwords

To recover a password in Oracle, simply connect under command line mode on the server:

#sqlplus /nolog      
SQL>conn / as sysdba      
SQL>alter user Username identified by PASSWORD;

To reset your Orable database password:

Your password file should be under <orahome>\database\PWD<SID>.ora.

Delete it and run the Oracle password utility from the command prompt:

c\:Oracle\ora92\database>ORAPWD file=PWD<SID>.ora password={password} entries={however many}.

The <password> is your new sys password. After you log in as sys you can change it and create new passwords for system.

 

 

How do I get the list of tables in an Oracle database from SQL Plus?

Solution

To list the tables in the schema of the current user:

SELECT table_name FROM user_tables;

List the tables accessible by the user:

SELECT table_name FROM all_tables;

List all the tables (must be ADMIN):

SELECT table_name FROM dba_tables;

zimbra backup.sh

#!/bin/bash
# Zimbra Backup Script
# This script is intended to run from the crontab as root
# Date outputs and su vs sudo corrections by other contributors, thanks, sorry I don’t have names to attribute!
# Free to use and free of any warranty! Daniel W. Martin, 5 Dec 2008
# Updated by Scott Harwell on 02/03/2013 to try to circumvent ldap 85 GB allocated file.
# Also, this backup only backs up locally; ncftp has been commented out.
# Outputs the time the backup started, for log/tracking purposes
echo Time backup started = $(date +%T)
before=”$(date +%s)”
# Live sync before stopping Zimbra to minimize sync time with the services down
# Comment out the following line if you want to try single cold-sync only
rsync -avHK –exclude ‘data/ldap/mdb/db’ –delete /opt/zimbra/ /media/backup/zimbra_backup
# which is the same as: /opt/zimbra /backup
# Including –delete option gets rid of files in the dest folder that don’t exist at the src
# this prevents logfile/extraneous bloat from building up overtime.
# Now we need to shut down Zimbra to rsync any files that were/are locked
# whilst backing up when the server was up and running.
before2=”$(date +%s)”
# Stop Zimbra Services
su – zimbra -c”/opt/zimbra/bin/zmcontrol stop”
sleep 30
# Kill any orphaned Zimbra processes
ORPHANED=`ps -u zimbra -o “pid=”` && kill -9 $ORPHANED
# Only enable the following command if you need all Zimbra user owned
# processes to be killed before syncing
# ps auxww | awk ‘{print $1″ “$2}’ | grep zimbra | kill -9 `awk ‘{print $2}’`
# Sync to backup directory
rsync -avHKS –exclude ‘data/ldap/mdb/db’ –delete /opt/zimbra/ /media/backup/zimbra_backup
# Sync LDAP Sparse Files (cp copies sparse files properly)
cp -r /opt/zimbra/data/ldap/mdb/db /media/backup/zimbra_backup/data/ldap/mdb/
# Restart Zimbra Services
su – zimbra -c “/opt/zimbra/bin/zmcontrol start”
# Calculates and outputs amount of time the server was down for
after=”$(date +%s)”
elapsed=”$(expr $after – $before2)”
hours=$(($elapsed / 3600))
elapsed=$(($elapsed – $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed – $minutes * 60))
echo Server was down for: “$hours hours $minutes minutes $seconds seconds”
# Create a txt file in the backup directory that’ll contains the current Zimbra
# server version. Handy for knowing what version of Zimbra a backup can be restored to.
su – zimbra -c “zmcontrol -v > /media/backup/zimbra_backup/conf/zimbra_version.txt”
# or examine your /opt/zimbra/.install_history
# Display Zimbra services status
echo Displaying Zimbra services status…
su – zimbra -c “/opt/zimbra/bin/zmcontrol status”
# Create archive of backed-up directory for offsite transfer
# cd /backup/zimbra
umask 0177
today=”$(date +%m-%d-%y)”
tar -zcvf “/media/backup/zimbra_backup_tars/mail.backup.$today.tgz” -C /media/backup/zimbra_backup .
####### SCOTT COMMENTED OUT AS NO TRANSFER AT THIS POINT
# Transfer file to backup server
#ncftpput -u <username> -p <password> <ftpserver> /<desired dest. directory> /tmp/mail.backup.tgz
#
#rm /tmp/mail.backup.tgz
#######
# Outputs the time the backup finished
echo Time backup finished = $(date +%T)
# Calculates and outputs total time taken
after=”$(date +%s)”
elapsed=”$(expr $after – $before)”
hours=$(($elapsed / 3600))
elapsed=$(($elapsed – $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed – $minutes * 60))
echo Time taken: “$hours hours $minutes minutes $seconds seconds”

MySQL Backup

#! /bin/bash

 

# your MySQL server’s name
SERVER=test.net

# directory to backup to
BACKDIR=~/backups

# date format that is appended to filename
DATE=`date +’%m-%d-%Y’`

#———————-MySQL Settings——————–#

# your MySQL server’s location (IP address is best)
HOST=localhost

# MySQL username
USER=username

# MySQL password
PASS=password

# List all of the MySQL databases that you want to backup in here,
# each separated by a space
DBS=”db1 db2?

# set to ‘y’ if you want to backup all your databases. this will override
# the database selection above.
DUMPALL=y

#———————-Mail Settings——————–#

# set to ‘y’ if you’d like to be emailed the backup (requires mutt)
MAIL=y

# email addresses to send backups to, separated by a space
EMAILS=”1@gmail.com 2@inbox.com 3@goowy.com”

SUBJECT=”MySQL backup on $SERVER ($DATE)”

#———————-FTP Settings——————–#

# set “FTP=y” if you want to enable FTP backups
FTP=n

# FTP server settings; should be self-explanatory
FTPHOST=”ftp.server.com”
FTPUSER=”username”
FTPPASS=”pass”

# directory to backup to. if it doesn’t exist, file will be uploaded to
# first logged-in directory
FTPDIR=”backups”

#——————-Deletion Settings——————-#

# delete old files?
DELETE=y

# how many days of backups do you want to keep?
DAYS=3

#———————-End of Settings——————#

# check of the backup directory exists
# if not, create it
if [ -e $BACKDIR ]
then
echo Backups directory already exists
else
mkdir $BACKDIR
fi

if [ $DUMPALL = “y” ]
then
echo “Creating list of all your databases…”

mysql -h $HOST –user=$USER –password=$PASS -e “show databases;” > dbs_on_$SERVER.txt

# redefine list of databases to be backed up
DBS=`sed -e ‘:a;N;$!ba;s/\\n/ /g’ -e ‘s/Database //g’ dbs_on_$SERVER.txt`
fi

echo “Backing up MySQL databases…”
for database in $DBS
do
mysqldump -h $HOST –user=$USER –password=$PASS $database > \\
$BACKDIR/$SERVER-mysqlbackup-$database-$DATE.sql
gzip -f -9 $BACKDIR/$SERVER-mysqlbackup-$database-$DATE.sql
done

# if you have the mail program ‘mutt’ installed on
# your server, this script will have mutt attach the backup
# and send it to the email addresses in $EMAILS

if [ $MAIL = “y” ]
then
BODY=”Your backup is ready! Find more useful scripts and info at http://www.ameir.net”
ATTACH=`for file in $BACKDIR/*$DATE.sql.gz; do echo -n “-a ${file} “; done`

echo “$BODY” | mutt -s “$SUBJECT” $ATTACH $EMAILS

echo -e “Your backup has been emailed to you! \n”
fi

if [ $FTP = “y” ]
then
echo “Initiating FTP connection…”
cd $BACKDIR
ATTACH=`for file in *$DATE.sql.gz; do echo -n -e “put ${file}\n”; done`

ftp -nv < open $FTPHOST
user $FTPUSER $FTPPASS
cd $FTPDIR
$ATTACH
quit
EOF
echo -e “FTP transfer complete! \n”
fi

if [ $DELETE = “y” ]
then
find $BACKDIR -name “*.sql.gz” -mtime $DAYS -exec rm {} \\;

if [ $DAYS = “1” ]
then
echo “Yesterday’s backup has been deleted.”
else
echo “The backup from $DAYS days ago has been deleted.”
fi
fi

How to Grant Privileges to Users in MySQL

How to Grant Privileges to Users in MySQL

 

MySQL stores all its username and password data in a special database named mysql. You can add users to this database and specify the databases to which they will have access with the grant command, which has the syntax.

sql> grant all privileges on database.* to username@”servername” identified by ‘password’;

The next step is to write the privilege changes to the mysql.sql database using the flush privileges command.

sql> flush privileges;

ALTER TABLE syntax – MySQL

ALTER TABLE syntax – MySQL

 

You can then import it into a MySQL table by running:

 

#load data local infile ‘file.csv’ into table tablename

fields terminated by ‘,’

enclosed by ‘”‘

lines terminated by ‘\n’

(field1, field2, field3)

Basic MySQL Commands

Basic MySQL Commands

 

To login (from unix shell) use -h only if needed.

#mysql -h hostname -u root -p

Create a database on the sql server.

mysql> create database [databasename];

List all databases on the sql server.

mysql> show databases;

Switch to a database.

mysql> use [db name];

To see all the tables in the db.

mysql> show tables;

To see database’s field formats.

mysql> describe [table name];

To delete a database.

mysql> drop database [database name];

To delete a table.

mysql> drop table [table name];

Show all data in a table.

mysql> SELECT * FROM [table name];

Creating a new user.

# mysql -u root -p

mysql> use mysql;

mysql> INSERT  INTO user (Host,User,Password)  VALUES(‘%’,’username’,PASSWORD(‘password’));

mysql> flush privileges;

Change a users password from unix shell.

 

 

 

 

#mysqladmin -u username -h hostname  -p password ‘new-password’

Change a users password from MySQL prompt. 

 

 

# mysql -u root -p

mysql> SET PASSWORD FOR  ‘user’@’hostname’ = PASSWORD(‘password’);

mysql> flush privileges;

Recover a MySQL root password.

 

 

 

 

# /etc/init.d/mysql stop

# mysqld_safe –skip-grant-tables  &

# mysql -u root

mysql> use mysql;

mysql> update user set  password=PASSWORD(“newrootpassword”) where User=’root’;

mysql> flush  privileges;

mysql> quit

# /etc/init.d/mysql stop

# /etc/init.d/mysql  start

 

Update a root password.

# mysqladmin -u root -p oldpassword newpassword

Allow the user “user1” to connect to the server from localhost 

 

 

 

 

 

# mysql -u root -p

mysql> use mysql;

mysql> grant  usage on *.* to user1@localhost identified by ‘password’;

mysql> flush  privileges;

Give user privilages for a database.

 

 

 

 

 

mysql> grant all privileges on  databasename.* to username@localhost;

mysql> flush privileges;

or

# mysql -u root -p

mysql> use mysql;

mysql> INSERT  INTO user  (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv)  VALUES (‘%’,’databasename’,’username’,’Y’,’Y’,’Y’,’Y’,’Y’,’N’);

mysql>  flush privileges;.

Load a CSV file into a table.

mysql> LOAD DATA INFILE ‘/tmp/filename.csv’ replace INTO  TABLE [table name] FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\n’  (field1,field2,field3);

Dump all databases for backup.

 

 

 

 

 

#mysqldump -u root -ppassword –opt  >/tmp/alldatabases_backup.sql

Dump one database for backup.

 

 

 

 

 

#mysqldump -u username -ppassword –databases  databasename >/tmp/databasename.sql

Dump a table from a database.

 

 

 

 

 

mysqldump -c -u username -ppassword  databasename tablename > /tmp/tablename.sql

Restore database (or database table) from backup.

 

 

 

 

 

mysql -u username -ppassword databasename  < /tmp/databasename.sql

Setup Mysql Replication Between Linux(master) & Windows XP(Slave)

Step 1 – Configure the Master Server

First we have to edit /etc/mysql/my.cnf. We have to enable networking for MySQL, and MySQL should listen on all IP addresses, therefore we comment out these lines (if existant):

#skip-networking

#bind-address            = 127.0.0.1

Furthermore we have to tell MySQL for which database it should write logs (these logs are used by the slave to see what has changed on the master),

which log file it should use, and we have to specify that this MySQL server is the master. We want to replicate the database exampledb, so

we put the following lines into/etc/mysql/my.cnf:

server-id               = 1

log_bin                 = /var/log/mysql/mysql-bin.log

binlog_do_db            = exampledb

 

Then we restart MySQL:

/etc/init.d/mysql restart

Then we log into the MySQL database as root and create a user with replication privileges:

 

mysql -u root -p

Enter password:

 

Now we are on the MySQL shell.

mysql>GRANT REPLICATION SLAVE ON *.* TO ’slave_user’@’%’ IDENTIFIED BY ‘<some_password>’; (Replace<some_password> with a real password!)

mysql>FLUSH PRIVILEGES;

 

Next (still on the MySQL shell) do this:

mysql>USE exampledb;

mysql>FLUSH TABLES WITH READ LOCK;

mysql>SHOW MASTER STATUS;

 

The last command will show something like this:

+—————+———-+————–+——————+

| File          | Position | Binlog_do_db | Binlog_ignore_db |

+—————+———-+————–+——————+

| mysql-bin.006 | 183      | exampledb    |                  |

+—————+———-+————–+——————+

1 row in set (0.00 sec)

 

Write down this information, we will need it later on the slave!

Then leave the MySQL shell:

 

mysql>quit;

 

Step 2 – Configure the Slave Server(Windows XP)


Edit the c:\program files\mysql\mysql server 5.0\my.ini

server-id=2

master-host=db01.yourdomain.net (or IP address)
master-port=3306
master-user=slave_user
master-password=password

Step 3 – Restart Mysql Service 

goto> Control Panel>Administrative Tools>Services>Mysql

Restart Service

mysql > Stop slave;

mysql>CHANGE MASTER TO MASTER_HOST=’192.168.10.175?, MASTER_USER=’slave_user’, MASTER_PASSWORD=’password’,MASTER_LOG_FILE=’mysql-bin.000008?,MASTER_LOG_POS=98;

mysql > Start slave;

Assign Virtual IPs to your NIC

Edit file /etc/sysconfig/network-scripts/ifcfg-eth0.

DEVICE=eth0

BOOTPROTO=static

BROADCAST=192.168.0.255

HWADDR=00:00:00:00:00:00

IPADDR=192.168.10.2

NETMASK=255.255.255.0

NETWORK=192.168.10.0

ONBOOT=yes

TYPE=Ethernet

GATEWAY=192.168.10.1

 

Make a copy of this in the same directory naming the new file ifcfg-eth0:1

# cp ifcfg-eth0 ifcfg-eth0\:1

 

Modify /etc/sysconfig/network-scripts/ifcfg-eth0:1 file. Modification are in bold

DEVICE=eth0:1

BOOTPROTO=static

BROADCAST=192.168.0.255

HWADDR=00:00:00:00:00:00

IPADDR=192.168.10.101

NETMASK=255.255.255.0

NETWORK=192.168.10.0

ONBOOT=yes

TYPE=Ethernet

GATEWAY=192.168.10.1


# cp ifcfg-eth0\:1 /etc/sysconfig/networking/devices/

# cp ifcfg-eth0\:1 /etc/sysconfig/networking/profiles/default/

 

Now, bring up the new interface using the ifup script:

# ifup eth0\:1

Running ifconfig, the new interface should be listed. You can also check it by pinging:

# ping 192.168.10.101

How to take Linux backups powered by Rsync

RSync backups data and does it very clean and well. Rsync only transfers those data that have been modified and changed so that the destination host has an exact replica from the source host. Rysnc is a command line backup tool that handles data transfers in an effective and secure manner like any other known commercial backup softwares around. Rync blends in and integrates flawlessly with linux shell commands combined linux I/O redirections.

Here’s an altenative approach based from recent entry on creating data backups from simple one to an enterprise backup data sets using rsync.

Man Rsync:

Rsync uses a reliable algorithm to bring remote and host files into sync very quickly. Rsync is fast because it just sends the differences in the files over the network instead of sending the complete files. Rsync is often used as a very powerful mirroring process or just as a more capable replacement for the rcp command. The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection, using an efficient checksum-search algorithm.

INSTALLATION:
~~~~~~~~~~~~~~~~

Rsync installation is installed by default System Tool group installation. If rsync is not available from command line and from rpm database, you can install from yum repo using yum like so

# yum -y install rsync

To verify that rsync has been installed successfully

# rpm -qa rsync

There are two different approach on establishing rsync communication between two hosts.

First is by using a remote-shell program such as ssh or rsh. If you want to use this approach, it is required that openssh server or an active ssh connection is present from both sending and receiving host. Openssh installation and configuration would not be covered from this entry. This entry would assume that ssh daemon service is currently configured and listening properly to assigned host port.

Secondly, is by using rsync listening INETD service directly.

This entry hope to cover both of them two worlds.

Rsync usage from command line terminal
======================================

Transfer and/or update files from local host into a remote host using rsync
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Basic rsync argument is to specify file glob, a source and a destination folder. Destination can be a local host or a remote host. A basic example to transfer from local to remote would be

# rsync -t *.mp3 remoteusername@remotehost:remote_destination_folder

The above would transfer, using rsync, all *.mp3 files from current local directory into remote_destination_folder of remotehost using remoteusername for authentication. A destination host can be locally or remote host and can be specified as hostname or IP address.

Legend:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-t preserve time of selected files
*.mp3 selected files to be transferred
remoteusername bash enabled user account from destination host
remotehost destination host where remoteusername is allowed to have access
remote_destination_folder destination folder from destination host owned and accessible
by remoteusername
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For recursive traversing of directory folders for transferring data from current host to another host using rsync, this would be like so

# rsync -avrzt /var/www myuser@server1:/var/backup/
Legends:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-a archived mode enabled
-v verbosed mode enabled
-t preserve time stamp
-z compression transfer enabled
-r resursive mode enabled
/var/www selected folder or files glob source location
myuser user account from destination host
server1 destination host
/var/backup destination folder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The above command would issues rsync with verbose mode enabled, compression enabled, arhived mode of rsync data transfer/update. Rsync transfers files and folders from /var/www (including the www folder) into /var/backup folder of server1 host using myuser as login credentials. The /var/backup from destination host is owned or writeable by myuser . All rsync files are created with file ownership and permission owned by myuser having 600 file mode. The transfer would be done preserving symbolic links, devices, attributes, permissions and ownerships of files.

# rsync -avz /var/www/ myuser@server1:/var/backup/www

Appending / from selected file glob like the above command issues the same rsync command with same argument. The only difference is that source folder is not created .

Transfer files from remote host to local host using rsync
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# rsync -avrzt remoteusername@remotehost:remote_source_folder destination_folder
# rsync -avrz myuser@server1:/var/backup/www /var/www/

To transfer multiple files with different file extension from local host to remote host using rsync with file glob would be

# rsync -avrz file1.mp3 *.doc myuser@server1:/home/folder/location

To transfer multiple files from multiple directory sources using rsync would be

# rsync -avz `find /etc -name *.conf` user@remotehost:/user/folder

Linux command line tools when combined with each other creates another set of power tools. The above command searches all *.conf files from /etc folder and transfer them to /usr/folder of remotehost via rsync and using user the user login name. This can be handy if you like to backup specific pattern of files from your system or user accounts individual address books, files like that.

To transfer multiple files from multiple directory with some file excemptions using rsync and grep from local to remote would be like so:

# rsync -avz `find /etc -name *.conf | grep -v yum.conf` user@remotehost:/user/folder

Alternatively,

# rsync -avz $(find /etc -name *.conf | grep -v yum.conf) user@remotehost:/user/folder

and for multiple file rsync with multiple file from multiple source location with multiple file transfer exceptions would be like so

# rsync -avz `find /etc -name *.conf | grep -v ‘yum.conf\|xorg.conf’` user@remotehost:/user/folder

To transfer of all your back up files ending in .tar file extension from any location would be like so

# rsync -avz `find / -name *.tar` user@remotehost:/user/folder

You will noticed that rsync can transfer data at high speed rate using rsync algorithm specially if those files and folders to be transferred are existing already from remote host.

To transfer multiple file(s) with multiple exclusions using rsync would be like so:

# rsync -avz * user@remotehost:/location –exclude=*.php –exclude=*.mp3

To transfer files in batch mode based from file lists using rsync would be

Assuming listing.txt is created with contents like below

# cat listing.txt
~~~~~~~~~~~~~~~~~~~~~
files0123.txt
files0124.txt
files6124.txt
files6126.txt

snipped

files32126.txt
~~~~~~~~~~~~~~~~~~~~~

and feeding the above file to rsync as batch mode input like so

# rsync -avzt –files-from=listing.txt user@remotehost

:/destination/

To rsync multiple folder source location using rsync would be like so

# rsync -avz –files-from=/home1 /home2 user@remotehost:/destination/

If both location contains abc.txt, the latest abc.txt would be transferred to remote host. If /home1/www exist and /home2/www exist, the files from both source kicatuib would be merged into /destination/www .

Fire up two new terminal windows, and from the first window, establish ssh connection from local to remote rsync destination. Then from the second windows try to issue these rsync command. You will notice that rsync never ask any password any more since there is an existing ssh connection with local host to remote host.

More rsync arguments
====================

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-W transfer the whole files without considering any update changes from existing destination file or folder
–progress show progress bar and/or percentage
-4 prefers IPv4
-6 prefers IPv6
–bwlimit=KBPS execute rsync with bandwidth limit rate in KBPS
-h display a more human readable screen output
–log-file=FILE dumps file activity into a file
–ignore-existing ignores already existing copy from destination host
–max-size tells rsync to avoid transferring files larger than specified size like
–max-size=10m avoid file transfer with 10MB in filesize
–port tells rsync to connect to rsync server with a different port, default is 873
–stats tells more file transfer info and rsync algorithm stats on the fly
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

At this point, be reminded to kick the black ninja box to refresh possible monitor related eye strains.

Using Rsync in Daemon Xinetd Mode
=================================

Edit /etc/xinetd.d/rsync and modify

disable = yes
to
disable = no

To run rsync in deamon mode via xinetd, make sure you have similar lines from your /etc/xinetd.d/rsync file like shown below:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = –daemon –config=/etc/rsync/rsyncd.conf -v
log_on_failure += USERID
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Create /etc/rsync/rsyncd.conf as a default conf file for rsync in daemon xinetd mode.

Sample rsyncd.conf file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uid = rsync-user
gid = rsync-user
use chroot = yes
read only = yes
pid file = /var/run/rsyncd.pid

# access list, edit the IP network block to suit your needs
hosts allow=192.168.0.0/255.255.0.0 192.168.1.0/255.255.255.0
# deny anything else
hosts deny=*

# limit connections
max connections = 5
#greeting file
motd file = /etc/rsync/rsyncd.motd
#log file
log file = /var/log/rsync.log

#rsync shared folder
[myrsync]
#make your UID/GUID above owns the below folder and files
#all files and folder would be seen by rsync client
path=/home/rsync-user/rsync-folder
comment = Linux Rsync Server
exclude = *.mp3

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Create rsync greeting MOTD file like so

# cat /etc/rsync/rsyncd.motd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Welcome to my Rsync Server!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Restart xinetd service for the changes to take effect like so

# service xinetd restart

Verify that rsync is running as xinetd daemon service mode using one tool like ss

# ss -a | grep rsync
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LISTEN 0 0 *:rsync *:*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Rsync uses port 873 as its default port for xinetd service. Make sure it is also open from your current firewall settings. A sample firewall rule for opeing rsync from your firewall would be like so

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 873 -j ACCEPT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# service iptables restart

If you wish to have a passwordless rsync, you need to refer to passwordless/passphraseless ssh from one of last month’s entry.

Rsync in daemon mode via command line
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

An alternative to run rsync in daemon mode is by specifying it from command line. Like so

# rsync –daemon –address host-IP-address –config=/etc/rsync/rsyncd.conf -v –port=873

Legend:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
–daemon enables rsync to be run as daemon mode from terminal
–port specifies port number to use
–config specified rsync conf file
host-IP-address IP address where to bind rsync from
-v enables verbose mode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Listing out files and folder from rsync server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To list out the files from rsync server, simply point your rsync client to the host running rsync in daemon mode or server mode. To test your rsync server from a client linux host would be like so

# rsync host-IP-address::

Alternatively,

# rsync rsync://host-IP-address/myrsync
# rsync rsync://host-IP-address/myrsync/folder1

From the above rsync command, you should be seeing files from /home/rsync-user/rsync-folder folder from rsync server you defined from /etc/rsync/rsyncd.conf.

Syncing File and Folders from Rsync Server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To sync and download files from rsync server.

# rsync rsync://host-IP-address/myrsync/folder1 .

The above command downloads files including the whole folder1 folder from rsync server and saves it to current directory

# rsync rsync://host-IP-address/myrsync/folder1/ .

The above command downloads only files from folder1 to current folder location

Rsync Log Monitoring
~~~~~~~~~~~~~~~~~~~~

Monitoring rsync server messages for any errors or system messages would be like so

# tail -f /var/log/rsync.log

Final Note:

Rsync can also be used for source code control and management for delivering a centralized and distributed sync source codes from rsync server to group of programmers or source developers among departments, more like a CVS approach.

Using rsync linux command provides many abilities and benefits. To name a few, mirror an entire harddisk or partitions, folders and files, entire domain websites, mail spools for replica servers, user’s home folder, a mirror FTP site and much more.

Backup like the enterprise way, use RSync.

How to Prevent the reuse of old passwords

For RHEL/Fedora distribution 

To remember the last 5 passwords, add the line below to the file /etc/pam.d/system-auth file:

password sufficient /lib/security/pam_unix.so use_authtok md5 shadow remember=5

For Debian/ubuntu distribution

To remember the last 5 passwords, add the line below to the file /etc/pam.d/common-password file:

password sufficient /lib/security/pam_unix.so use_authtok md5 shadow remember=5