This script does an svn hotcopy of a subversion repository and then rsyncs it to an external location. Easy to script, nice trouble-free way of maintaining subversion backups.
#!/bin/bash
export RSYNC_RSH=/usr/bin/ssh
# some variables in case they change later
server=destination.com # where we are sending the backup to
user=miguel
tempcopy=/home/${user}/svnbackup
dest=/media/disk/svnserver/svnbackup
# example svn repository
# make the backup with svnadmin hotcopy
svnadmin hotcopy /data1/svn/repo/ ${tempcopy}/repo/
# rsync it to the external hard drive on my desk
rsync -aHPvz ${tempcopy}/repo/ "${user}@${server}:${dest}/repo/"
# finally, remove the backup on svnserver to free up some space
rm -rf ${tempcopy}/repo
It had never occured to me before, but suddenly I had the need to run a script on the last day of every month, in order to get the right results per month.
Given that a month's last date can be 28, 29 30 or 31, it wasn't as simple as usual!
After a bit of googling I found the easy solution. Simply get the crontab to run every day, but add into the crontab a check to see if tomorrow's date of the month is '01'. If it isn't, do nothing. If it is, then continue with the rest of the script.
36 14 * * * [ `date -d tomorrow +%d` -eq '01'] && /execute/the/real/script.sh
Edit: Hmm, got a syntax error there:
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``' /bin/sh: -c: line 1: syntax error: unexpected end of file
Ah well, since I'm only executing a shell script, I just added this to my script:
#!/bin/bash
TODAY=`/bin/date +%d`
TOMORROW=`/bin/date +%d -d "1 day"`
# See if tomorrow's day is less than today's
if [ $TOMORROW -lt $TODAY ]; then
(real script executes here)
exit 0
fi
exit 1
Both articles from Sébastien Wains's blog
Named pipe
You may know “screen”, tool that can help you put your session on hold and and get back to it whenever you want.
Described below is a way to share your session with someone… this can come in handy while doing support or if you just want to share your session for some reasonYou should follow the following steps carefully
User 1 will work in the terminal
User 2 will watch what user 1 is doing1. User 1 :
mkfifo /tmp/file2. User 2 :
cat /tmp/file3. User 1 :
script -f /tmp/fileUser 1 can start working, user 2 will be able to follow his work, user 1 should type ctrl + D if wanting to stop sharing the session…
If user 2 tries to input something, the connection to the pipe will be lost and you should get back to step 2.
Screen method
This is a great way if you can’t install anything on the machine. If you are able to get “screen” installed, screen provides a much easier way, which allows all connected users to interact on the shared session. The named pipe method only allowed one user to watch what the other user was doing.
So here it goes…
1. user 1 connects to the machine and type the command “screen”
2. inside the screen terminal, user 1 hits ctrl + a and then type “:multiuser on”
3. user 2 joins in by typing “screen -x”
4. other users can join as described at point 3Both users are now sharing the session.
Ctrl + a then d will close the screen session
Links :
Source : http://linuxhelp.blogspot.com/2005/01/screen-window-manager-for-console....
VERY simple rsync script. It rsyncs a remote directory across to a local one. There's no special reason why I did this, other than I wanted to run the script on my local machine. It could just as easily rsync a local directory to a remote one.
#!/bin/sh
export RSYNC_RSH=/usr/bin/ssh
origin=remote.machine.com # the remote machine to rsync from
user=miguel # the remote user
rsync -aHPvz "${user}@${origin}:/remote/files/" "/local/files/"
I run ssh-keygen -t rsa and create a password-less key on the remote machine, and copy the .pub file into my authorized_keys. This way I can run this script on a cron, say in the middle of the night, and not have to be around to enter a password at the prompt.
Ctrl-a -> go to the start of command line
Ctrl-e -> go to the end of command line
Ctrl-p -> previous command in history
Ctrl-n -> next command in history
Ctrl-f -> next character in command line
Ctrl-b -> previous character in command line
Ctrl-r -> reverse search in history file
Ctrl-d -> delete current character
Ctrl-k -> delete from the prompt to the end of command line
Ctrl-_ -> undo (yes, but limited)
Meta-< -> go to beginning of history file
Meta-> -> go to end of history file
Meta-f -> go to next word in command line
Meta-b -> go to previous word in command line
Meta-d -> delete next word in command line (from the actual position of the prompt)
#!/bin/bash
# Basic backup script
# Written in February 2010
# Set to q to disable verbosity
VERBOSITY="v"
# The program we're using to backup
PROGRAM="rsync"
# The arguments to the program
OPTIONS="-aHP$VERBOSITY"
# The remote machine we're backing up
SERVER="max"
# The local disk to back up to
DISK="/mnt/disk"
# An array of shares on $SERVER to back up
SHARES=(
hr
finance
clients
operations
newsvn
svn
backup/jira
backup/svn/noah
backup/dbbackups/kontrol_live
backup/dbbackups/god
)
# The magic
for share in ${SHARES[*]}; do
echo "Backup of $share beginning at" `date`
$PROGRAM $OPTIONS $PROGRAM://$SERVER/$share/ $DISK/$share/
echo "Backup of $share completed at" `date`
done