apples723
Posts: 80
Joined: Sat Jun 22, 2013 3:13 pm

back up script

Mon Jul 01, 2013 10:11 pm

how can i write a script in idle 3 to back up a certin folder on my raspberry pi to my computer

DrMag
Posts: 63
Joined: Sat Jun 01, 2013 7:59 pm

Re: back up script

Tue Jul 02, 2013 1:40 am

You should look at the shutil module.

apples723
Posts: 80
Joined: Sat Jun 22, 2013 3:13 pm

Re: back up script

Tue Jul 02, 2013 2:05 pm

i looked at it but im a total noob just got my pi week and a half ago and it doesn't make sense

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: back up script

Tue Jul 02, 2013 2:08 pm

is your computer windows ?
then install something like freesshd
and rsync fro your RPi to a windows directory
or
use winscp on the windows machine to connect to your RPi and backup that way
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

DrMag
Posts: 63
Joined: Sat Jun 01, 2013 7:59 pm

Re: back up script

Tue Jul 02, 2013 5:11 pm

The shutil module gives you the functionality to copy files around within a filesystem. You can, for example, do this to copy a file from one directory to another:

Code: Select all

import shutil
original_file = "/path/to/file.ext"
new_file = "/newpath/to/newfile.ext"
shutil.copy(original_file, new_file)
Of course, the filenames and paths would be whatever is appropriate for what you're doing. (Assigning those strings to the variable names is optional-- you can also just put them directly into the shutil.copy() function call.)

I see now it sounds like you want to transfer over a network too, though, so that changes it somewhat. shutil would still be useful depending on how you have your system set up.

RaTTuS asked my major question; in addition, I'm assuming you have a Model B, and it's connected to your network? Another good method (in that case) is to use pyssh, though it would also require an ssh server on your other computer. If it's a Mac or linux box, you're set. For a windows box, there are a few good options, including freessh. Bitvise also makes a good windows ssh server that is free under particular circumstances that you'll likely meet. Yet another option using ssh would be to mount your computer's destination directory to your RPi with sshfs, then you can just treat it as though you're moving/copying files around on the local filesystem. Very cool functionality.

Alternatively, it could be a fun project for you to just write a python program on each side (you'll need python on your destination computer as well) and use the python socket module to transfer data directly using UDP or TCP. If you're willing to get your hands dirty, that is. 8-)

Return to “Python”