Jump to content

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


Recommended Posts

Posted (edited)
Case sensitive - it is echo, not Echo.

DERP! Should have noticed that >.< echo is blue in nano, whereas Echo is white.

 

Should be --host=

Also derp. I'd updated the .txt document I have of what I'm doing but not the actual script itself. Someone get me another brew -_- I need more caffeine.

 

Not sure about this. I think you need to drop the full path from the archive name. You are in the directory you want so /mnt/ntfs/ should not be needed, just wp_data.tar.bz2 .

Fair play.

 

you probably need to cd /home/user (or somewhere) before you unmount the share.

Worth giving it a bash.

 

# Mount the backup share
mount -t cifs /// -o username=,dom=,password= /mnt/ntfs

# Make the backup share the current directory, create WebServer subdir
cd /mnt/ntfs
mkdir WebServer

# Timestamp
date >> ./WebServer/backup.log
echo "Started" >> ./WebServer/backup.log

# Backup MySQL database
mysqldump --host=localhost --user= --password= wordpress > ./WebServer/db_backup.sql

# Backup Wordpress application and assets
tar -cjf ./Webserver/wp_data.tar.bz2 /usr/share/wordpress

# Unmount backup share
echo "Finished" >> ./WebServer/backup.log
cd /home/user
unmount /mnt/ntfs

 

Now to run it..

~/scripts$ sudo ./backup.sh
tar: Removing leading '/' from member names
$ _

So still not clocked that thing about the leading '/' (could it be because of /usr/share/wordpress rather than usr/share/wordpress?)

 

Aside from that, WebServer folder appears in the share, 1KB backup.log, 43KB db_backup.sql and 11,256KB wp_data.tar.bz2.. SUCCESS!!

Edited by Garacesh
Posted

The leading / on tar is, I think, to do with tar not wanting to package up full paths. You can avoid it by changing the options to

 

tar -jcPf

Posted (edited)

Yep, that's worked great! Woohoo.

 

[color="#00FFFF"]# Mount the backup share, make current dir backup-misc/WebServer[/color]
mount -t cifs //[i][/i]/ -o username[color="#008000"]=[/color][i][/i],dom[color="#008000"]=[/color][i][/i],password[color="#008000"]=[/color][i][/i] /mnt/ntfs
[color="#0000FF"]cd[/color] /mnt/ntfs/WebServer

[color="#00FFFF"]# Timestamp[/color]
[color="#0000FF"]echo[/color] [color="#FFFF00"]"Last backup began: "[/color] [color="#008000"]>[/color] ./backup.log
date [color="#008000"]>>[/color] ./backup.log

[color="#00FFFF"]# Backup MySQL database[/color]
mysqldump --host[color="#008000"]=[/color]localhost --user[color="#008000"]=[/color][i][/i] --password[color="#008000"]=[/color][i][/i] wordpress > ./wp_db_backup.sql

[color="#00FFFF"]# Backup Wordpress application and assets[/color]
[color="#0000FF"]tar[/color] -cjf ./wp_data.[color="#0000FF"]tar[/color].bz2 /usr/share/wordpress

[color="#00FFFF"]# Final timestamp, unmount backup share[/color]
[color="#0000FF"]echo[/color][color="#FFFF00"] " - Finished: "[/color] [color="#008000"]>>[/color] ./backup.log
date [color="#008000"]>>[/color] ./backup.log
[color="#0000FF"]cd[/color] /home/user
unmount /mnt/ntfs

 

Decided to go for > first rather than >> to stop the file growing and growing exponentially. It's not really a huge concern I guess, it's only a small text file, but still.

 

Edit: Yellow no show up too good..

 

Edit: So to set that as an automated nightly job, I'm looking for..

$ crontab -e
0 5 * * * /home/user/scripts/backup.sh >/dev/null 2>&1
^O 

right?

Edited by Garacesh
Posted

The file won't grow exponentially. It will grow linearly. The advantage of allowing that is you can see when it started to go wrong (which may give you a clue as to what change killed it).

 

You need it to run as root, so

 

sudo crontab -e (will edit the root crontab)

 

Your cron syntax looks OK, 5 mins after mindnight every day. I wouldn't bother with any of the gubbins after the script name. Output will be logged to /var/syslog.

Posted

Handy!

Well, the backup works. Runs at 5am rather than 00:05 but the point is, it works in a rudimentary sense.

Incremental would have been better, I guess, but we won't be having this server for an amazing length of time, it's just a test bed, so it's no real loss.

Posted
Handy!

Well, the backup works. Runs at 5am rather than 00:05 but the point is, it works in a rudimentary sense.

 

Your cron entry says 00:05:

 

$ crontab -e
# min hour dayofmonth month dayofweek command
  0    5    *          *       *      /home/user/scripts/backup.sh >/dev/null 2>&1

 

You probably meant 5 0 * * * .

Posted
Incremental would have been better, I guess, but we won't be having this server for an amazing length of time, it's just a test bed, so it's no real loss.

You can do incremental backups of MySQL and if you explore the manpage for tar, it is possible to update an archive or create a new archive of files that have changed. It does make both the script and any restore process more complex.

 

MySQL Making an Incremental Backup

Using tar to Perform Incremental Dumps

Posted
Your cron entry says 00:05:

 

$ crontab -e
# min hour dayofmonth month dayofweek command
  0    5    *          *       *      /home/user/scripts/backup.sh >/dev/null 2>&1

 

You probably meant 5 0 * * * .

 

No, no, I want it at 5 past midnight (Well, actually I want it at Midnight but it's always awkward for timestamping as some languages interpret that as just before and some interpret it as just after, so five minutes past relieves that issue)

But the files created are timestamped 05:00

Wait, confused.. You say my cron entry says 00:05 (which is what I want) but then say that I actually want 5 0 * * * (which would mean my cron entry doesn't say 00:05)..?

Posted
No, no, I want it at 5 past midnight (Well, actually I want it at Midnight but it's always awkward for timestamping as some languages interpret that as just before and some interpret it as just after, so five minutes past relieves that issue)

But the files created are timestamped 05:00

Wait, confused.. You say my cron entry says 00:05 (which is what I want) but then say that I actually want 5 0 * * * (which would mean my cron entry doesn't say 00:05)..?

 

Oh, oops. Your original cron entry in fact says 5am.

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...