Wednesday 19 October 2011

Backup Server to Server Linux

1: ssh user@server1.com
2: enter passwrod:
3: Checkout your server available space
4: Command is # df -h
5: If you have enough space on the server to compress your data then compress first
6: tar -cvzf yourfilename.tar.gz yourfilename
7: or you can take the whole directory to compress
8: tar -cvzf yourdirectory.tar.gz yourdirectory/.*
9: You have take the backup of important files and folders.
10: Take backup of
-->Configuration files
-/etc/httpd/conf/httpd.conf
-/etc/php.ini
-All the configuration files of application you are running on the server.
11: Take backup of /var/www/html/.* in CentOs and /var/www/html/sites-availble in ubuntu.
12: When the tar.gz is completed then transfer the compressed data to another server for backup.
13: If you do not have much more space on the server then you can transfer the open data from one server to another one.
13: Login to your second server through ssh
14: Create a folder there with the name of backup-server1 if you have enough space.
15: Now come back to terminal 1st user@yourserver1.com ( server 1)
16: Copy all the tar files to server2 user@yourserver2.com by the following commands
17: scp -drp folder1.tar.gz user@server2.com:~/backup-server1/
18: scp -drp folder2.tar.gz user@server2.com:~/backup-server1/
19: scp -drp folder3.tar.gz user@server2.com:~/backup-server1/
20: scp -drp folder4.tar.gz user@server2.com:~/backup-server1/

all Your data will be backup to server2.
21: To Transfer the open file run the following commands
scp -drp /var/www/html/site1.com/.* user@server2.com:~/backup-server1/var/www/html/site1.com
but first you have to create a folder on the server server2 in /var/www/html/site1.com then run the command above.
22: Check your data size on both the servers.

23: Backup /var/log/.* Directory as well and delete all the log files to create space on your server.

This is an overview of how to take backup of server and make it possible to transfer to another server. if you are facing any issue on taking backup. i will be happy to assist you from here. so feel free to post the issue you are facing.

Regards:
Imran shahmeer

Thursday 6 October 2011

How to change Crontab Editor and Add Cron Jobs to Server

Most of the time newbie install the cron and accept the terminal editor sed for crontab, which brings them towards difficulties.
In this Tutorial we have shown that how to change the Crontab Editor from sed(default Crontab Editor) to your desired one, like VIM,GEDIT,NANO or VI.

Follow the Procedure given bellow you will be able to add jobs to cron successfully.

login to your server through ssh Press(Alt+Ctrl+T) open terminal
root@pfserver-desktop1# ssh username@servername.com ( you can use IP instead of servername.com)
passwrod:

root@pfserver-desktop$
checkout your cron is installed
root@pfserver-desktop# ps -aux
: if no entry is there for cron then

root@pfserver-desktop# /etc/init.d/cron start or service cron start
started

now type the command on your terminal

root@pfserver-desktop# env EDITOR=vim crontab -e
Enter
It will open a file of crontab for you where you can add your jobs.

Now we want to add some jobs to our crontab file.

1: First you have to write a shell script or txt file and save it on your server in a known location

2: shell scrip is saved with the name of file.sh

3:root@pfserver-desktop# chmod +x file.sh
to operate as script file

4: After creating a file test it manually wither it is running correctly or not.
like i have created srag.sh file in /bin directory so i will check it manually

5: root@pfserver-desktop#/bin/sarg.sh daily

The output is :
SARG - Daily / Weekly / Monthly - Squid proxy usage reports creation tool
Written by Imran Ullah
Version: 20050202
Usage: /bin/sarg.sh [OPTIONS]
Allowed options:
manual, Create Manual report
today, Create Today report
daily, Create Daily report
weekly, Create Weekly report
montly, Create Monthly report
..............................................
SARG: No records found 20039, reading: 99.81%
SARG: End
SARG: Records in file: 20039, reading: 100.00%

Now i am adding this script to crontab file. Where in the above command the daily is used as an argument to run the script.

6:root@pfserver-desktop# crontab -l
no job for root user

7: root@pfserver-desktop# env EDITOR=vim crontab -e

# Edit this file to introduce tasks to be run by cron.
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezone.
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# For more information see the manual pages of crontab(5) and cron(8)
# m h dom mon dow command

8: Press i for insert and type the following command

01 20 * * * /bin/sarg.sh daily
10 20 * * 1 /bin/sarg.sh weekly
20 20 29 * * /bin/sarg.sh monthly

Save and Exit!

9: Check out your crontab

crontab -l
This will show you the jobs you added to crontab file.

10: First line in the jobs added to crontab file the figure 01 means every minutes, 20 means 8:00 P.M, and the * means all the times, So this script will be executed every day, Each month and in Every week at 8:01 Evening, And the out put directory is defined in the sarg.sh file.

11: In second line the 1 is used for Monday (week: Sunday =0..6) so on every Monday at 8:01 P.M This script will run and produce the out put.

12: In third line 29 means Date of the Month. This will create out put on Every 29th of the month at 8:01 PM at any day of the week every year.

12: restart the service of cron for confirmation that there is no error in the new posted jobs.

service cron restart
restart OK

now can ENJOY the a cup of TEA at 08:01 * * *! Have a nice day.

May this tutorial will be helpful for you!
your comments will appreciated for further discussion!

Saturday 1 October 2011

Accessing Squid Reports Through Web Local Lan

open your configuration file of webalizer or sarg. which one want to show the squid reports.
for sarg the following steps will be followed:

sudo vim /etc/sarg/sarg.conf

find
/output_dir /var/www/html/squid-reports


comment this line with # sign
and write another line just below the commented line
output_dir /var/www/sarg

save and exit
:wq!

now create a folder with a name of sarg in /var/www/

sudo mkdir /var/www/sarg
sudo chomd -R 775 /var/www/sarg

now run the sarg command from CLI
yourserver# sarg -e
completed:

checkout your server ip:
ifconfig

open a browser in any pc connected in LAN and access the url
http://your-server-ip/sarg
you will see the squid reports on your browser through web from any where in LAN.

Enjoy and Good Luck.
for any query just comment here or for quick reply you can put an email your query.
shahmeer09@gmail.com