Online backup script
#1
I'd like to ask local Linux gurus for help.

I have a linux system runing an MCServer instance (Gallery, on a RasPi). I'd like to have a script that:
- runs every N hours (N ~~ 24)
- packs folders "gal" and "world" and files "Gallery.cfg" and "Gallery.sqlite" into a 7z file
- names the resulting 7z file based on local date (and possibly time), format yyyy-mm-dd hh-mm-ss.7z
- uploads the resulting 7z file to a remote host running Linux via scp; scp needs to use a specified username and a private key in a specified file. The destination folder on the remote host should be based on the year and month of the upload (some/remote/path/yyyy-mm/yyyy-mm-dd hh-mm-ss.7z). The folder may need to be created if it doesn't exist.
- uploads the resulting 7z file to a remote SMB public-writable share, again in a folder named with year and month.

I have no idea how to write such a script, where to put it and how to register it so that it's run every day. Can you help me out? Thanks.
Reply
Thanks given by:
#2
(11-28-2014, 08:06 AM)xoft Wrote: - runs every N hours (N ~~ 24)
- packs folders "gal" and "world" and files "Gallery.cfg" and "Gallery.sqlite" into a 7z file
- names the resulting 7z file based on local date (and possibly time), format yyyy-mm-dd hh-mm-ss.7z
- uploads the resulting 7z file to a remote host running Linux via scp; scp needs to use a specified username and a private key in a specified file. The destination folder on the remote host should be based on the year and month of the upload (some/remote/path/yyyy-mm/yyyy-mm-dd hh-mm-ss.7z). The folder may need to be created if it doesn't exist.
- uploads the resulting 7z file to a remote SMB public-writable share, again in a folder named with year and month.

Does it need to be "7z"? This is not installed at linux systems by default. Usually it would be "tar" or better "tgz" which also can be used in Windows if you have the prg for 7z installed

Using scp is simple, and the keyfile just need to be inside the ".ssh" folder of the user which runs the script.

I can do that script for you, and also will try to explain the commands you need to execute for registration etc. Just right now i have no time Smile


Edit:
- is the smb share already mounted or not? If yes hopefully using mount cifs or smbclient?!
Reply
Thanks given by:
#3
I'd very much prefer 7z to save on diskspace, tgz archives are almost twice in size. I don't mind installing a 7zip compressor on the system.

I don't have the smb share mounted, but if you tell me how to, I can do it (supposing it's a one-time action). Neither the RasPi nor the remote windows systems are ever restarted, so it should keep the share available for all time, I guess.
Reply
Thanks given by:
#4
Thanks to @nouseforname I now have an (almost) working share accessible from the raspi. Here's the instructions:
Quote:Try to install cifs at your raspberry:
sudo apt-get install cifs-utils

if this works without any problem:
sudo mkdir /mnt/backup
sudo mount -t cifs //smbhost/path/folder /mnt/backup -o user=UserName


if no errors, you can check if the content if right:
ls /mnt/backup

or also create a file inside this folder and check if you can see it at the windows host
touch /mnt/backup/mytest.txt
So far only the last part fails, the mounted share is writable only by root.
Reply
Thanks given by:
#5
(11-28-2014, 10:59 PM)xoft Wrote: sudo mkdir /mnt/backup
sudo mount -t cifs //smbhost/path/folder /mnt/backup -o user=UserName
Did you use a user from the windows machine was there a promt for password?

Quote:ls /mnt/backup
Could you see some files from windows machine?


Quote:touch /mnt/backup/mytest.txt
So far only the last part fails, the mounted share is writable only by root.

This will be solved by using the right user for the smb mount or running the backup script as root.

I think the smb mount should be done on reboot, so i will try to explain how to do that later.


Now next part, the scp connect. Try to use this script at the raspberry. It will connect and create a new folder and copy one file inside. Make sure the destination path is in the home folder of the user you are using

#!/bin/bash

user="USER"
host="example.com"
port=22
dest="/path/of/create/newfolder"
src="1234.567"


touch 1234.567
ssh -p $port $user@$host "mkdir -p $dest" && scp -rp -P $port $src $user@$host:$dest

exit


let me know if this works for you. actually, do you have some experience with linux?
Reply
Thanks given by:
#6
Here we go:

its mostly tested in steps, but of course not complete. i think it should work like expected. just take care the instructions.


https://github.com/nouseforname/MCbackup


Let me know it it works or not. I will also post it at my site later



Edit: just recognized, i forgot to implement 7z ( i hate 7z... its too much windows^^) anyway i will try to add it

Edit 2: Added updated script with 7z or tar function to choose
Reply
Thanks given by:
#7
When I run the script, 7z complains about missing file, it seems it doesn't like the apostrophes in the names:
Code:
WARNINGS for files:

/home/pi/mcs-gallery/'world/' : No such file or directory
----------------
WARNING: Cannot find 1 file

(repeated for all 4 items)
Are the backslashes in front of the apostrophes in your script (line 69) supposed to be there, or is the forum playing tricks with the code?
Reply
Thanks given by:
#8
(11-30-2014, 05:17 AM)xoft Wrote: Are the backslashes in front of the apostrophes in your script (line 69) supposed to be there, or is the forum playing tricks with the code?


No this is an escape from forum, sry didnt see that. Here is github
https://github.com/nouseforname/MCbackup

Or from my site:
http://nouseforname.de/
Reply
Thanks given by:
#9
I think I've ironed out the last wrinkles in the script. I'll make a PR to your GitHub with the fixes I needed to make.

We'll see if it works automatically on 3:30, it's supposed to provide complete backups of the Gallery server on http://mc-server.xoft.cz/GalleryBackup/
Reply
Thanks given by:
#10
Yes, it works! Smile
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)