Backup /var/www/ to Windows Share

Soldato
Joined
5 May 2003
Posts
4,515
Location
UK
Hi guys

I want to backup a website to a windows share. I'm guessing the best way of doing this would be to tar /var/www/ up, then somehow copy to a windows share and use CRON so schedule this nightly.

Any ideas on the best way to go about this? I'd like it to work even if the server has been restarted.

I'm using the latest version of ubuntu server and have samba installed.

Thanks
 
This is really easy with a quick shell script. I'll sort of mock one up for you here but since I suck at scripting and I'm not on a real computer ATM there might be some syntax errors.

Code:
#!/bin/bash
tar -cvzf /home/ethos/www.tgz /var/www

mount -t cifs -o username=server_user,password=server_password //192.168.44.100/share_name /media/remotebackup

cp /home/ethos/www.tgz /media/remotebackup/

umount /media/remotebackup

You just save your script, make it executable, and set it up as a daily cron job or whatever.
 
This worked for me and crontab is all setup now, thanks for the help:

#!/bin/bash
tar -cvzf /home/administrator/www.tgz /var/www

mount -t cifs //server/company /mnt/remotebackup -0 username=administrator,password=password,domain=xx

cp /home/administrator/www.tgz /mnt/remotebackup/

umount /mnt/remotebackup

:cool:
 
That's going to overwrite yesterday's backup with today's. It'd probably be more clever to give each backup a name based on today's date.

I don't know enough bash to tell you how to do this. :o Somebody here does.

Also, be aware that this doesn't grab any databases in use. If you've got a database on your server you should back that up too.
 
That's going to overwrite yesterday's backup with today's. It'd probably be more clever to give each backup a name based on today's date.

I don't know enough bash to tell you how to do this. :o Somebody here does.

Also, be aware that this doesn't grab any databases in use. If you've got a database on your server you should back that up too.

It's ok, i've also setup mysql to backup the database to a folder within the intranet, so this will get backed up too.

The intranet is over 1GB and we do full daily backups, so i'm not that fussed that it overwrites each night.
 
The only things I need to do now is rename the box as it's currently down was intranettest (i'm migrating our intranet from a mandrake 9.1 server that hasn't been touched for about 5 years, fun!).

I don't think it's simply a case of editing etc/hostname :D
 
Well what I was getting at with that was that if the site gets hacked or otherwise broken on Wednesday and nobody notices the subtle change made until Friday you can't just restore from backup because your Thursday backup contains the broken bits.
 
True, I think it's fairly low risk in terms of a security breach (famous last words!).

I'll look into it, unless anyone else is handy with it?

Oh, i've changed the hostname, needs to be changed in /etc/hostname and /etc/hosts to work properly.
 
That's going to overwrite yesterday's backup with today's. It'd probably be more clever to give each backup a name based on today's date.

I don't know enough bash to tell you how to do this. :o Somebody here does.

Also, be aware that this doesn't grab any databases in use. If you've got a database on your server you should back that up too.

I'd probably make a change like this:

#!/bin/bash
DAY=`date +%a`

tar -cvzf /home/administrator/www.$DAY.tgz /var/www

mount -t cifs //server/company /mnt/remotebackup -0 username=administrator,password=password,domain=xx

cp /home/administrator/www.$DAY.tgz /mnt/remotebackup/

umount /mnt/remotebackup
which should then give you www.Mon.tgz, www.Tue.tgz etc ... which would at least give you a weeks worth of backups to go back to. That assumes that covers a long enough period. You could use a longer period in by varying the date command but then you may need to put some form of housekeeping in place to prevent file build up.
 
Perhaps there's something that 'm missing but can't you just run an FTP server on the Windoze machine and transfer the tar file over that way?
 
Back
Top Bottom