Jump to content

[Command Line Server] Setting an automated incremental backup to a network location


Recommended Posts

Posted

I've recently set up a web server in the Command Line version of Ubuntu Server to set up Wordpress and I've managed (somehow :|) to get that working, admittedly just by following tutorials and modifying commands where appropriate.

 

Now I want to set it up to do an incremental backup, probably just weekly for now as it's a test server and not due to go live for some time, but I'm struggling to figure it out. There's so many different ways of doing it I think I'm just suffering a bit of an option overload (doesn't help that I went in 'at the deep end' and chose not to use the GUI server)

 

Any advice on where to begin?

Posted
Use mysqldump to backup the database. You can do this from a remote server (windows or nix) or locally if you don't want to open up the server to accept remote connections to the MySQL Database. Use rsync to backup the user files (and possibly the whole application) to a remote server.
Posted

I have basically no linux experience guys. Just worth pointing out.

 

The place I want to back up to on the network is an NTFS share, but can be NFS if need be. I understand a lot of backups are made by 'mounting' the share, copying over and then unmounting? But I don't really know how any of that works or where to begin with it.

 

Given it's just a VM I wouldn't usually care about mucking around because if I break it I can just reset it and try again, except we've given the Wordpress credentials to the member who is rebuilding our website and I don't want to risk losing that work.

Posted
I have basically no linux experience guys. Just worth pointing out.

 

 

Well, you must have accumulated some linux experience to set up the server?!

 

mysqldump is a command line utility to produce a database backup. It should look like :

 

mysqldump -h  -u  -p   > 

 

It should normally be installed on a lamps system assuming you are running MySQL not some other database.

 

You may be able to mount a share :

mount -t cifs /// -o username=myntaccount,password=mypassword /mnt/ntfs

{ Then
  change to mopunted dir, 
  do database backup, 
  do copy/tar of wordpress assets path, 
  do copy/tar of wordpress application
}

unmount /mnt/ntfs

(You may find you need the cifs utils, in which case sudo apt-get install cifs-utils).

 

That should be it. Put the code in a shell file and then instantiate a cron job to run it every day (or whatever interval suits). If any of that is still too cryptic or doesn't work - shout and I'll do my best to help.

Posted
Well, you must have accumulated some linux experience to set up the server?!

Um, ish? lol.

Installing the iso onto the VM and going from there. Following instructions (though I did have to alter them a little) to set up network settings, Apache, MySQL, PHP and Wordpress. Ballsed it up once, reinstalled OS, gave it another try, got it right.

 

I'll give that lot a try, thanks!

Posted (edited)

I'm getting:

Couldn't chdir to /mnt/ntfs: No such file or directory
/home/user/backup.sh: line 5: syntax error near unexpected token 'do'
/home user/backup.sh: line 5: ` do database backup'

 

mount -t cifs //10.114.192.61/backup-misc/Webserver -o username=WebBackup,password=[i][/i] /mnt/ntfs

{ Then
change to //10.114.192.61/backup-misc/webserver/wordpress,
do database backup,
do copy/tar of wordpress assets path,
do copy/tar of wordpress application
}

mysqldump -h localhost -u root -p [i][/i] wordpress > //10.114.192.61/backup-misc/webserver/mysql

unmount /mnt/ntfs

Edited by Garacesh
Posted (edited)

Ah. Sorry. The { Then ... } stuff is pseudo code. It should look more like :

 

# Mount the share on which backup files will go. 
mount -t cifs //10.114.192.61/backup-misc/Webserver -o username=WebBackup,password= /mnt/ntfs

# Make the backup share the current working directory
cd /mnt/ntfs

# Create a backup of the database
mysqldump -h localhost -u root -p  wordpress > db_backup.sql

# create a backup of the wordpress application
tar -cjf wp_code.tar.bz2 /var/www/wordpress

# Create a backup of the wordpress assets (user data)
tar -cjf wp_data.tar.bz2 /var/wordpress_data

# Unmount the backup share
unmount /mnt/ntfs

 

You will need to change some of that. Run it one command at a time and get each one working. You will need to create the /mnt/ntfs before you mount something there. You can change that to any path you want (/mnt/backup) might be good!

Edited by pcstru
Posted (edited)
Do you actually have the mountpoint available (/mnt/ntfs)? if not will need to mkdir it first before mounting into it.

Ah, no. I hadn't. So I ran 'sudo mkdir /mnt/ntfs' and that worked.. So that's a start.

Sorry, very little linux experience. Baby steps ^_^;;

 

[font=Fixedsys][b][color="#40E0D0"]# Mount the backup share[/color]
mount -t cifs //10.114.192.61/backup-misc/Webserver -o username=WebBackup,password=[i][/i] /mnt/ntfs

[color="#40E0D0"]# Make the backup share the current directory[/color]
[color="#0000FF"]cd[/color] /mnt/ntfs

[color="#40E0D0"]# Backup MySQL database[/color]
mysqldump -h localhost -u root -p [i][/i] wordpress > /MySQL/db_backup.sql

[color="#40E0D0"]#Backup Wordpress application and assets[/color]
[color="#0000FF"]tar[/color] -cjf wp_code.[color="#0000FF"]tar[/color].bz2 /Wordpress/var/www
[color="#0000FF"]tar[/color] -cjf wp_data.[color="#0000FF"]tar[/color].bz2 /Wordpress/var

[color="#40E0D0"]# Unmount backup share[/color]
unmount /mnt/ntfs[/b][/font]

 

This now gets me:

[font=Fixedsys][b]user@Wordpress-Server:~$ sudo bash /home/user/backup.sh
[957150.530443] CIFS VFS: cifs_mount failed w/return code = -13
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
/home/user/backup.sh: line 8: /MySQL/db_backup.sql: No such file or directory
tar: removing leading '/' from member names
tar: /Wordpress/var/www: Cannot stat: No such file or directory
tar: Existing with failure status due to previous errors
tar: removing leading '/' from member names
tar: /Wordpress/var: Cannot stat: No such file or directory
tar: Existing with failure status due to previous errors
/home/user/backup.sh: line 15: unmount: command not found
user@Wordpress-Server:~$ _[/b][/font]

 

Username and password are definitely correct, though googling the error code leads me to a post saying the share needs to be open to EVERYONE?

Edited by Garacesh
Posted (edited)

Take it one line at a time, so first run the mount command on it's own and see what you get. So to mount my share on the fileserver I run :

cd /home/pcstru
mkdir tmp
sudo mount -t cifs //ourfileserver/pcstru$ -o username=pcstru,password=secret /home/pcstru/tmp 

 

Then if I

cd tmp
ls -al

 

I see my shared area.

 

You won't need sudo in the shell file because we will eventually run it from a cron as root, but you will need it in the command line.

 

Top tip : In a unix shell, up arrow should recall previous commands. Tab will complete commands (or display a list of possible options).

Edited by pcstru
Posted (edited)

Cron job should already be set up with @Midnight /home/user/backup.sh.. I'm just currently needing sudo to run it manually, I presume?

(also sorry to Midnight for mentioning you. Whoopsie.)

 

Okay, so here goes.

 

user@Wordpress-Server:~$ cd /mnt/ntfs
user@Wordpress-Server:/mnt/ntfs$ sudo mount -t cifs //10.114.192.61/backup-misc/webserver -o username=WebBackup,password=[i][/i] /mnt/ntfs
[sudo] password for user:[i] (I hadn't executed a command in a while..)[/i]
[957150.530443] CIFS VFS: cifs_mount failed w/return code = -13
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
user@Wordpress-Server:/mnt/ntfs$ _

 

Now, \\10.114.192.61\backup-misc\webserver does exist (I'm definitely supposed to be using forward slashes in Linux, right?) and WebBackup does have access to it. However, WebBackup is a LOCAL account on 10.114.92.61 - could that be causing the issue? I have also tried username=10.114.192.61\WebBackup and [email protected] but neither have produced any different a result.

Edited by Garacesh
Posted
Your local user account cannot mount filesystems. Normally this is done by root. Either use sudo to mount the file system (configure sudo not to prompt for a password or your script will break) or you can define the mount point in the fstab and give the user option which will allow non-privileged users to mount it.
Posted

Did you do the sudo apt-get install cifs-utils (and did it install without error)?

 

You can try specifying the domain along with the user name and password : username=,dom=,password=

Posted (edited)
Did you do the sudo apt-get install cifs-utils (and did it install without error)?

I did, yes. There were no errors.

 

You can try specifying the domain along with the user name and password : username=,dom=,password=

Ah-hah! Now we're getting somewhere.

We've gone from Mount error 13, permission denied to mount error(2): No such file or directory.

However, /mnt/ntfs exists as I'm in it (executing from user@Wordpress-Server:/mnt/ntfs$) and backup-misc\webserver also exists

 

user@Wordpress-Server:/mnt/ntfs$ sudo mount -t cifs //10.114.192.61/backup-misc/Webserver -o username=WebBackup,dom=10.114.192.61,password=[i] [/i]/mnt/ntfs

Edited by Garacesh
Posted

10.114.192.61 is just our generic backup server for misc. projects (as opposed to our proper backup off-site server for the important stuff)

It's a NAS box that runs.. Some custom flavour of Linux. The share name is backup-misc

Posted

NFS is recommended for Linux <-> Linux file sharing via mounts. You might also want to think about using rsync

 

sudo mount -t cifs //10.114.192.61/backup-misc/Webserver -o username=WebBackup,dom=10.114.192.61,password= /mnt/ntfs

 

Drop the 'Webserver' in the cifs path. Also the domain is wrong, it should be the netbios name of the server.

Posted
Drop the 'Webserver' in the cifs path

 

sudo mount -t cifs //10.114.192.61/backup-misc/ -o username=WebBackup,dom=10.114.192.61,password= /mnt/ntfs

Aha, that has worked! Or at least.. It hasn't given me an error message.

 

Also the domain is wrong, it should be the netbios name of the server.

Really? It works with an ip address (apparently). If the IP address is fixed, what difference does it make to use the IP or the netbios name? Or is it just a best-practise thing?

Posted (edited)
sudo mount -t cifs //10.114.192.61/backup-misc/ -o username=WebBackup,dom=10.114.192.61,password= /mnt/ntfs

Aha, that has worked! Or at least.. It hasn't given me an error message.

Good! Write a file to it, unmount it and then mount it back up again. Check the file from somewhere else if possible.

Really? It works with an ip address (apparently). If the IP address is fixed, what difference does it make to use the IP or the netbios name? Or is it just a best-practise thing?

If the user WebBackup is local to that machine it won't matter. If you have AD and it's an AD user, then you probably want the netbios name which will tell it where to authenticate. (actually you can get rid of the dom=, it was the path instead of the sharename that was probably the problem).

 

On with the music : if that is all working, we want the backup for mysql :

 

mysqldump -h localhost -u  -p  wordpress > db_backup.sql

Edited by pcstru
Posted (edited)
Good! Write a file to it, unmount it and then mount it back up again. Check the file from somewhere else if possible.

sudo nano
testing
^O /mnt/ntfs/test.txt
^X

test.txt is created in the backup-misc share. Huzzah!

 

mysqldump -h localhost -u  -p  wordpress > db_backup.sql
-bash: db_backup.sql: Permission denied

 

Same result if I sudo and if I replace localhost with the actual server IP (I'm right to be using the IP of the linux server, right?)

Edited by Garacesh
Posted

Probably permissions on /mnt/ntfs

 

ls -al /mnt

 

Will show what the permissions are.

 

sudo chmod 777 /mnt/ntfs

 

will let anyone do anything but since we will be running as root, let's try the mysqldump running from your home area if you just cd without any path, it should take you /home/. Then run mysqldump in that dir.

Posted (edited)

user@Wordpress-Server:/mnt/ntfs$ cd
user@Wordpress-Server:~$ sudo mysqldump -h localhost -u  -p  wordpress > dv_backup.sql
-bash: db_backup.sql: Permission denied

 

Just to be safe I confirmed the credentials I'm using for the SQL database were correct (mysql --user= --password=) and didn't encounter any error

 

user@Wordpress-Server:~$ cd /mnt/ntfs
user@Wordpress-Server:/mnt/ntfs$ ls-al /mnt
total 8
drwxr-xr-x	3	root	root	4096	Sep	29	11:31	[color="#0000FF"].[/color]
drwxr-xr-x	22	root	root	4096	Sep	18	09:39	[color="#0000FF"]..[/color]
drwxr-xr-x	2	root	root	4096	Sep	29	10:58	[color="#0000FF"]ntfs[/color]

 

Edit:

sudo nano
testing file creation on remote share
^O /mnt/ntfs/testing.txt

This, as before, created a file in the share.

 

^O /mnt/ntfs/webserver/testing2.txt
[ Error writing /mnt/ntfs/webserver/testing2.txt: No such file or directory ]

Edited by Garacesh

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...