Hoping some one can help me out with an issue I have with my first program from the e-book "A byte of Python".
The e-book is based on Python 2.7.
Program: zip a source directory and format it with a particular "Name" and place it in the destination directory.
The E-Books code to do this task is:
import os
import time
# source directory of files to backup
source = ["/root/Documents/test"]
# target location for files to be backed up to
target_dir = "/root/Documents/Backup"
target = target_dir + os.sep
time.strftime("%Y%m%d%H%M") + ".zip"
# if target path does not exist, create it
if not os.path.exists(target_dir):
os.mkdir(target_dir)
# Command to zip files
zip_command = "zip -r {0}".format(target).join(source)
#run the backup
print "Zip command is:"
print (zip_command)
print "Running"
# Check to see if backup was successful
if os.system(zip_command) == 0:
print "Successfull backup to", target
else:
print "Backup Failed"
The error I am receiving is:
Zip command is:
/root/Documents/test
Running
Backup Failed
sh: 1: /root/Documents/test: Permission denied
Process finished with exit code 0
I have checked the permissions on the folders, attempted to run the code as super user etc.. but I am having no luck, I am extremely new to Python and don't really want to continue on with this e-book until I have found a resolution to this problem as it re-uses and refines this code as I go on.
I have a feeling the problem could be related to the zip_command?
Any help would be greatly appreciated.