Ok, this may be my last disaster recovery and backup blog for a long time. As you can probably tell from the title this blog entry is all about keeping backup strategies as cheap as possible.
My strategy is to backup all of my Windows and Linux servers to one central Windows server that is running a Tivoli backup agent. All of my servers are hosted elsewhere, and since it costs $99.00 per server to backup I am getting the most for my money by only backing a single server to tape/SAN. However that single server carries all of the files that need to be remotely backed up to tape/SAN.
My earlier posts show how to backup the Windows servers:
Windows backup bat script using xcopy
Also, how to backup the Windows Domain Controller:
Backup Windows Domain Controller using NTBACKUP via cmd
And I also showed how to backup a Linux server to a local file:
Linux backup using CRON to local directory
Now I will show how I moved the files backed up on the Linux servers to the Windows server prior to tape/SAN backup. I have decided to use Samba and mount a directory pointing to a shared folder on the Windows server. Lets begin:
- Create a share on the Windows server to use as your backup location.
- Create a user to use this share, and give the user permissions to use it.
- Pick, or create, a user that you’re going to use to backup the files. Log in as this user and type ‘id’ to get the numeric ID of the user in the Linux OS. (You will need it later.)
- Become ‘root’. (This will enable you to perform the next tasks without problems.)
- Install samba and samba-client if they are not installed yet.
yum install samba yum install samba-client
You will need to answer ‘y’ to when prompted.
- By default only the root user can mount or unmount a cifs, so we must open it to other users.
chmod 4755 /sbin/mount.cifs chmod 4755 /sbin/umount.cifs
- Now we need to make a directory to use as our mount point.
mkdir /mnt/sharename
- To enable our desired user to mount and unmount this we need to assign ownership to that user. Changing permissions with chmod is not enough.
chown userfrom#1 /mnt/sharename
- Now we need to edit the /etc/fstab file and add an entry. Replace the user ID of 500 with your user ID from #1. Replace sharename with your Windows share name. Replace WINDOWSHOST with your hostname or IP address. If you don’t know the shares run smbclient -L WINDOWSHOST
//WINDOWSHOST/sharename /mnt/sharename cifs credentials=/root/smblogin,uid=500,noauto,user 0 0
- Create/Edit a file /root/smblogin and put the following two lines in it.
username=WINDOWS USERNAME password=WINDOWS PASSWORD
- Now we must give our user from #1 access to the file, but still protect it.
chown userfrom#1 /root/smblogin chmod 600 /root/smblogin
- If you have IPTABLES active on your server you will need to make sure to add a policy to allow OUTPUT port 445.
- Log in as the user from #1
- Try to mount the share:
mount /mnt/sharename ls -la /mnt/sharename umount /mnt/sharename
- If that was successful you are now ready to write a script that will automate the moving of your backup files from the Linux to the Windows share. (Script/File = backup.sh)
#!/bin/sh mount /mnt/sharename cp -r /path/to/file.tar.gz /mnt/sharename/path/to/file.tar.gz umount /mnt/sharename
Of course you can add this to the end of the file described in Linux backup using CRON to local directory which would create a complete solution for backing up files, then relocating them to a remote Windows server.
- Next you will add an entry to the crontab of the user from #1 to happen automagically.
crontab -e -u userfrom#1
- Enter this into the crontab.
# Backup at 1:00 A.M. every day. Call 'man 5 crontab' for more information * 1 * * * /path/to/backup.sh
Now once this is all done you can rest a little bit easier knowing that your servers are backed up. I hear the beach calling me now….ttyl.
Comments
2 responses to “Backup files from Linux to a Windows server”