Posts Tagged automation

CIFS it is…


This is the final, fully tested and functional remote backup script for linux… Finally 🙂

#!/bin/bash
# A straght forward system backup script
#
LOGBASE=/var/log/backup/log
BACKUP_ROOT_DIR=”a/facts77 a/can”                       ## Backup dirs; do not prefix /
NOW=$(date +”%a”)                                       ## Get todays day
TSTAMP=$(date +”%l:%M:%S”)                              ## Get time stamp H:M:S
TDATE=$(date -I)                                        ## Get todays date
TAPE=”/oracle55vm_backup”                               ## Backup device name
TAR_ARGS=””                                             ## Exclude file
EXCLUDE_CONF=/root/.backup.exclude.conf                 ## Named file for file exclusion
LOGFILE=$LOGBASE/$TDATE.backup.log                      ## Backup Log file
FILELIST=$LOGBASE/$TDATE.backup.file-listing.log        ## Backup Log file list
UNAME=”xxx”
PWORD=”xxxXXXX”
SYSTEM=”`uname -n|cut -c 1-10`”
# Path to binaries
TAR=/bin/tar
MKDIR=/bin/mkdir
#
full_backup(){
local old=$(pwd)i
cd /
# Mount the samba destination
mount.cifs //bufvmfacts01/G/oracle55vm_backup $TAPE -o username=$UNAME,password=$PWORD
# Search the directory for files older than 7 days and delete them
find /oracle55vm_backup -type f -mtime +7|xargs -r rm -f
# Run the backup
tar -zcvf $TAPE/$SYSTEM.bak.`date -I`.tgz $BACKUP_ROOT_DIR # gzipping these
cd $old
}
# Make sure all dirs exits
verify_backup_dirs(){
local s=0
for d in $BACKUP_ROOT_DIR
do
if [ ! -d /$d ];
then
echo “Error : /$d directory does not exit!”
s=1
fi
done
# if not; just die
[ $s -eq 1 ] && exit 1
}
# Make some kind of status report
report_backup_info(){
touch $LOGBASE/$TDATE.backup.file-listing.log
cd $TAPE
echo ” ”
echo ”                        **** Backup Report ****”
echo ”                        ****   $TDATE  ****”
echo ” ——————————————————————————— ”
echo ” ################################################################################# ”
echo ” _________________________________________________________________________________ ”
echo ” ”
echo ” ”
echo ”  Backup start time: $TSTAMP”
echo ”  Operating System: `cat /etc/redhat-release`”
echo ” ”
echo ”  Size of the complete archive: `tar -ztvf $SYSTEM.bak.$TDATE.tgz|wc -c` Bytes”
echo ”  Size of the logged archive:   `cat $FILELIST|wc -c` Bytes”
echo ” ”
echo ”  File count of the completed archive: `tar -ztvf $SYSTEM.bak.$TDATE.tgz|wc -l` Files”
echo ”  File count of the logged archive:    `cat $FILELIST|wc -l` Files”
echo ” ”
echo ”  Remote CIFS Directory Listing:”
ls -lh
echo ” ”
echo ”  Disk Summary:”
df -h
echo ” ”
echo ” _________________________________________________________________________________ ”
echo ”                                                                                   ”
echo ” ################################################################################# ”
echo ” ——————————————————————————— ”
echo ” ”
cd –
} > $LOGFILE 2>&1
#
#
# Clean Up
clean_up(){
cd /
umount $TAPE # unmount the cifs mount
# Email the report
mail -s “System Backup $SYSTEM” gconklin@proserve-solutions.com < $LOGFILE
}
#
#
#### MAIN ####
#
# Make sure log dir exits
[ ! -d $LOGBASE ] && $MKDIR -p $LOGBASE
#
# Verify dirs
verify_backup_dirs
#
#
# Okay let us start backup procedure
# If it is Monday-Friday make a full backup;
# Weekend no backups
full_backup > $FILELIST 2>&1
#
#
# Make the simple report
report_backup_info
#
# Call the Clean UP function
clean_up

, , , , , , , , , , ,

Leave a comment

Backup Takanga… RHEL v5.5… Dancing with CIFS


OK, so a few days ago I did one of these to backup to an internal tape device… This time it’s going on a remote Windows share through CIFS… It is mostly the same as the tape version… I’m sure you’ll notice the subtleties… I am not much of a report writer so please excuse the ugliness of the info, but this really is primarily to facilitate a backup not report on it…  Anyway what I have come up with also uses a nifty find command to manage the remote Windows share in terms of number of backup files… I suggest doing something similar as you will eventually overrun the remote store if you don’t…   In any event.. the script below is fully tested and functional… as always 🙂

#!/bin/bash
# A straght forward system backup script
#
LOGBASE=/var/log/backup/log
BACKUP_ROOT_DIR=”a/facts77 a/can”                       ## Backup dirs; do not prefix /
NOW=$(date +”%a”)                                       ## Get todays day
TSTAMP=$(date +”%l:%M:%S”)                              ## Get time stamp H:M:S
TDATE=$(date -I)                                        ## Get todays date
TAPE=”/oracle55vm_backup”                               ## Backup device name
TAR_ARGS=””                                             ## Exclude file
EXCLUDE_CONF=/root/.backup.exclude.conf                 ## Named file for file exclusion
LOGFILE=$LOGBASE/$TDATE.backup.log                      ## Backup Log file
FILELIST=$LOGBASE/$TDATE.backup.file-listing.log        ## Backup Log file list
UNAME=”xxx”
PWORD=”xxxXXXX”
SYSTEM=`uname -n|cut -c 1-10`
# Path to binaries
TAR=/bin/tar
MKDIR=/bin/mkdir
#
full_backup(){
local old=$(pwd)i
cd /
# Mount the samba destination
mount.cifs //bufvmfacts01/G/oracle55vm_backup $TAPE -o username=$UNAME,password=$PWORD
# Search the directory for files older than 7 days and delete them
find /oracle55vm_backup -type f -mtime +7|xargs -r rm -f
# Run the backup
tar -zcvf $TAPE/$SYSTEM_backup.`date -I`.tgz $BACKUP_ROOT_DIR # gzipping these
cd $old
}
# Make sure all dirs exits
verify_backup_dirs(){
local s=0
for d in $BACKUP_ROOT_DIR
do
if [ ! -d /$d ];
then
echo “Error : /$d directory does not exit!”
s=1
fi
done
# if not; just die
[ $s -eq 1 ] && exit 1
}
# Make some kind of status report
report_backup_info(){
touch $LOGBASE/$TDATE.backup.file-listing.log
cd $TAPE
echo ”                                                                                   ”
echo ”                        **** Backup Report ****                                    ”
echo ”                        **** $TDATE ****                                           ”
echo ” ——————————————————————————— ”
echo ” ################################################################################# ”
echo ” ——————————————————————————— ”
echo “|                                                                                 |”
echo ”  Backup start time: $TSTAMP                                                                ”
echo ”  Operating System: `cat /etc/redhat-release`                                               ”
echo ”  Size of the complete archive: `tar -ztvf $SYSTEM.$TDATE.tgz|wc -c` Bytes                  ”
echo ”  Size of the logged archive:   `cat $FILELIST|wc -c` Bytes                                 ”
echo ”  File count of the completed archive: `tar -ztvf $SYSTEM.$TDATE.tgz|wc -l` Files           ”
echo ”  File count of the logged archive:    `cat $FILELIST|wc -l` Files                          ”
echo ”  Remote CIFS Directory Listing:                                                            ”
echo ”  ls -l                                                                                     ”
echo ”  Disk Summary:                                                                             ”
echo ”  `df -h`                                                                                   ”
echo “|                                                                                 |”
echo ” ——————————————————————————— ”
echo ” ################################################################################# ”
echo ” ——————————————————————————— ”
echo ”                                                                                   ”
cd –
} > $LOGFILE 2>&1
#
#
# Clean Up
clean_up(){
cd /
umount $TAPE # unmount the cifs mount
}
#
#
#### MAIN ####
#
# Make sure log dir exits
[ ! -d $LOGBASE ] && $MKDIR -p $LOGBASE
#
# Verify dirs
verify_backup_dirs
#
#
# Okay let us start backup procedure
# If it is Monday-Friday make a full backup;
# Weekend no backups
full_backup > $FILELIST 2>&1
#
#
# Make the simple report
report_backup_info
#
# Call the Clean UP function
clean_up

, , , , , , , , , ,

Leave a comment

wp-make-me-happy


Ok this is kind of a repeat but instead of editing the original post I thought I would just repost it in its new form.  I was working on setting up a backup blog of this very blog to have on a local server… I don’t know in case of disaster… actually it was to see what it looked like with some new themes I have as this site is somewhat limited in it’s design choices… not complaining mind you, just wanted to see what it would look like with some nifty designs I made… The original post, WordPress Automation, was from a while back and I had the need to actually make a new host just for this occasion as I had blown away all of my web servers recently (I don’t actually recall why…???).  I was going through my script pad and found a really simple setup script I wrote that was better than the original post I put here… although it really is the same thing just without any comments… LOL Sorry I take for granted that you are just going to trust that it works and run it !!! Scary 🙂  I did find a few hiccups however… My sed lines didn’t take although they are correct… and this was a stinker… The repo I like to create here, although mostly this is if you were going to run multiple vhosts on the same physical server, (It does allow you to have only 1 repo for ALL themes and plugins for ALL users) does NOT work with the Worpdpress Import plugin… So I ended up un-linking the plugins link and just re-instating the original one, good thing I copied it to a backup in this script instead of just blowing it away huh??? 🙂  As I stated earlier, the entire script is based on the setup that Virtualmin creates in its vhost creation module so if you are using something else or doing that manually, you may need to change this up a bit… 29 lines on this one… sorry 😦  LOL

#/bin/bash
#
echo “Make sure you have created this VHost using virtualmin FIRST…”
sleep 5
echo “OK… moving on then”
sleep 2
echo “Enter the name of your new site, then press [ENTER}”
read newblog
cd /home/$newblog/public_html
wget http://www.wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
rm -Rf latest.tar.gz
mv wordpress/* .
rm -Rf wordpress
chmod 777 .
cd /home/$newblog/public_html/wp-content
mv themes bak.themes # <– Just in case we hose everything 😦
mkdir -p /var/www/repo/themes
ln -s /var/www/repo/themes /home/$newblog/public_html/wp-content/themes
mv plugins bak.plugins
mkdir -p /var/www/repo/plugins
ln -s /var/www/repo/plugins /home/$newblog/public_html/wp-content/plugins
cd ../
cp wp-config-sample.php wp-config.php
sed -i ‘s/putyourdbnamehere/’$newblog’/’ wp-config.php
sed -i ‘s/usernamehere/’$newblog’/’ wp-config.php
sed -i ‘s/yourpasswordhere/’$newblog’/’ wp-config.php
chown -R $newblog:$newblog *
# EOF

, , , , , , , ,

Leave a comment

I am no arTist, but it works…


Hey, I like to script as much as the next guy, but I have always wondered why as a UNIX/Linux Admin/Engineer there are so many “similar” instances of issues and a plethora of examples on-line, yet very few, if any, complete (and functionally tested) interactive automated programs (if I don’t call it a program, even though it is not a “program,” it remains a script and we are stuck in a loop).  Anyway, much of what I do and I suspect what you do as well if you are reading this, kinda needs to be done pretty fast… ya know on the fly and it is quite repetitious.  So why not have a tool kit so to speak to perform these recurring tasks, instantly?  In a previous post I listed my Zimbra maildrop checker… this is in the same vein, however that was just a tool to discover information and then you have to manually execute the fix.  This one does it all for you and asks only a few questions.  I don’t know… maybe I am barking up the wrong tree here.  I guess in reality what I am trying to make is a command line Webmin?  Even though I love Webmin, I still cannot give up the command line…. LOL.  Hmmm… maybe I should just learn Perl and make these things FOR Webmin… Below is a little ditty to reduce an LV then extend another LV with the realized free PE.

#!/bin/bash
# Filesystem resize:
# for some filesystem to be reduced to grow another filesystem(s)
#
df -h
echo “Enter the filesystem you are unmounting, including the ‘/'”
read unmountfs
fuser -mv $unmountfs # <– or whatever fs you are unmounting
for i in `fuser -mv $unmountfs|grep -v PID`; do kill -9 $i; done
read -p “If this looks OK, Press any key to continue.”
lvol=`df -H $unmountfs|grep -v $unmountfs|grep -v File`
umount $unmountfs
sleep 1
echo “Using the information above, answer the following questions…”
sleep 2
e2fsck -f $lvol
echo “Enter the NEW reduced size of the lv; i.e. 2G, 200M, etc…”
read newsize
resize2fs $lvol $newsize
lvreduce -L $newsize $lvol
mount $unmountfs
#
# Now lets extend the other filesystem(s)
#
echo “Check your FREE PE now…”
vgdisplay |grep “Free  PE / Size”
df -h
freepe=`vgdisplay |grep “Free  PE / Size”`
echo “Enter the name of the full LV name you wish to extend”
read fullv
echo “Enter no more than `vgdisplay |grep “Free  PE / Size”|awk ‘{print $5}’` Physical Extents”
read PE
lvextend -l +$PE $fullv
echo “Now compare the original FREE PE to the new FREE PE”
echo $freepe
vgdisplay |grep “Free  PE / Size”
df -h
# EOF

Please keep in mind that I have NOT written any logic into this one yet… so… If you f’ something up… you might be in trouble.  I guess I have taken into assumption that whomever is using this knows what I am doing and can at least make fun of my “less than Earth shattering” scripting…

I am no arTist (pronounced r-Tee-st), but it works. 🙂

, , , , , , , , , , , , , ,

Leave a comment

WordPress Automation


OK so I had a few minutes to spare today and I  decided to finalize this mini-automation script for WordPress installs.  Keep in mind that  the assumption is made that you have used Virtualmin to create the preliminary aspects, vhost, mysql, doc root, etc… If not… this ain’t gonna work as it is.  I guess I could work up a more in-depth script to include these aspects, in fact that is how I started this idea in the first place, but the aspects of virtualmin really are pretty extensive and since I am using that to manage the vhosts anyway I just skipped that part, I mean why try to improve on a great integration aspect, besides it is unlikely I could do it better anyway.  I would however like to translate this piece into a Perl mod to be added to the virtualmin GUI, that would be a cool improvement.

#/bin/bash

#

echo “Make sure you have created this VHost using virtualmin FIRST…”

sleep 5

echo “OK… moving on then”

sleep 2

echo “Enter the name of your new site, then press [ENTER}”

read newblog

# You need these if you are NOT using virtualmin FIRST !!

# mkdir /var/www/html/$newblog

# useradd -c ‘$newblog user’ -p ‘$newblog’ $newblog

# chown -R $newblog:$newblog $newblog

cd /home/$newblog/public_html

wget http://www.wordpress.org/latest.tar.gz

tar xzf latest.tar.gz

rm -Rf latest.tar.gz

mv wordpress/* .

rm -Rf wordpress

chmod 777 .

# Link the themes & plugins from the default repo

# This makes the assumption that you actually HAVE a repo for themes and plugins…

# If you don’t this ain’t gonna do what we need it to !!

cd /home/$newblog/public_html/wp-content

mv themes bak.themes # <– Just in case we hose everything 😦

# Make the link directorie(s), if necessary and link ’em up

mkdir -p /var/www/repo/themes

ln -s /var/www/repo/themes /home/$newblog/public_html/wp-content/themes

mv plugins bak.plugins

mkdir -p /var/www/repo/plugins

ln -s /var/www/repo/plugins /home/$newblog/public_html/wp-content/plugins

cd ../

cp wp-config-sample.php wp-config.php

#

#

# Final directions

# Open the editor if needed but SED will do what you need

# vi wp-config.php

sed -i ‘s/putyourdbnamehere/’$newblog’/’ wp-config.php

sed -i ‘s/usernamehere/’$newblog’/’ wp-config.php

sed -i ‘s/yourpasswordhere/’$newblog’/’ wp-config.php

chown -R $newblog:$newblog *

# EOF

If you need webmin/virtualmin/cloudmin (I HIGHLY recommend them) you can spin this off:

# Virtualmin/Webmin/Cloudmin Installation

# cd /usr/src

# wget http://software.virtualmin.com/gpl/scripts/install.sh

# sh install.sh

# wegt http://cloudmin.virtualmin.com/gpl/scripts/cloudmin-gpl-redhat-install.sh

# sh cloudmin-gpl-redhat-install.sh

And that’s it! Just navigate to your new URL (assuming that you made the proper DNS entries…) and configure WordPress from its admin console.  I also thought this tutorial on SED was pretty useful although what I used here is very basic, just in case you need something more.

http://www.grymoire.com/Unix/Sed.html

Happy Blogging 🙂

, , , , , , , , , ,

3 Comments

WordPress 1 2 3 (… 4 5 6?)


I thought I would add a quick How-To on installing WordPress where it is not already present… Redundant? Well that’s OK… It can be a lot of fun to mess around with WordPress (designing), especially if you don’t know PHP (like me).   So this tutorial… if you can even call it that… will get you started on basically any linux server, however I am partial to centOS (currently centOS5.4) so these steps are tested and certified to work on only CentOS release 5.4 (Final).  Shouldn’t take more than 10 minutes to do this so that is not so bad right?  Oh and my base install is basically CD1 (.iso1) of the centOS release with no options selected… so this is a totally bare bones OS, no GUI no nuttin’.  That being said, I have really lost track of what I have on the system (which is silly because that was the purpose of doing this as a ‘bare-bones’ build… I guess that’s what you get when you don’t have a specific purpose in mind BEFORE you build a system) that was a pre-req for WordPress so I will just spew out an RPM listing for you… although the install will certainly complain if you don’t have anything beyond what I am listing in the body of the guide.  Maybe I will put that list @ the bottom of the post… Hmmm.. why can’t I add scroll bars here??? Odd, well anyway…

Here we go…

wordpress setup:

# Create a local non-root user (if not already present)
# Check defaults first:
[root@centOS54 wordpress]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
# now add the user:
useradd -c ‘Garot Conklin’ gmc <– Hey, that’s me 🙂 This can obviously be anything you want
passwd gmc
# Navigate to /var/www/html/
# create dir /wordpress
mkdir wordpress
Install required packages:
yum install httpd php mysql mysql-server php-mysql perl-Net-SSLeay <– Oops forgot one… perl-Net-SSLeay
# start and test apache2
start mysql:

service mysqld start

I know basically nothing about database installations so just follow these directions and you will be fine as well, what I mean is that WordPress will function, LOL.  That being said, this config certainly works, but may not be correct or the ‘optimal’ configuration.

# configure mysql:
mysqladmin -u root password ‘XXXXXX’ <– ya this may not be very secure… and may defeat the purpose of setting up the non-root user… LOL (maybe that’s not funny?)

This next command gets you into the database admin role: (That may not have been entirely clear)
[root@centOS54 wordpress]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.77 Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> insert into
-> host(host,db,Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv)
-> values(‘linuxbox’, ‘%’,’Y’,’Y’,’Y’,’Y’,’Y’,’Y’);
Query OK, 1 row affected (0.00 sec)

mysql> insert into
-> user (host, user, password)
-> values(‘localhost’, ‘gmc’, password(‘XXXXXXXX’));
Query OK, 1 row affected, 3 warnings (0.00 sec)

mysql> quit
Bye
# Create the database and name it ‘wordpress’
[root@centOS54 wordpress]# mysqladmin -u root -p create wordpress <– You can name the database whatever you want here
Enter password:
[root@centOS54 wordpress]# mysqladmin -u root -p reload
Enter password:

# Fetch wordpress
wget http://wordpress.org/latest.tar.gz
extract it into /var/www/html/wordpress
# Edit wp-config-sample.php:
vi wp-config-sample.php

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpress’);

/** MySQL database username */
define(‘DB_USER’, ‘root’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘XXXXXXXX’); <– replace all the XXXXXXX’s with the real password (in case that was not obvious?)

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

Re-name it:
cp wp-config-sample.php wp-config.php

# Reload/re-start daemons <– I don’t recall if these last 2 reloads were even necessary… doesn’t hurt though
mysqladmin -u root -p reload
service httpd restart

Done !

Navigate to http://<IP/hostname>/wordpress/wp-admin and off you go WordPress-ing !! 🙂

Oops.. almost forgot the RPM listing — Nope it is just too big of a list without the scroll bars… that are oddly stripped out of my code when I ‘update’ the page??? Maybe that is restriction of the free hosted blog? Anyway, it is not really necessary… you will know what you need outside of anything listed here… Hope this helped at least someone… LOL 🙂

, , , , , , , , ,

Leave a comment