Skip to content

Commit

Permalink
Merge pull request #1 from TRMSC/rmdev
Browse files Browse the repository at this point in the history
Merge rmdev branch
  • Loading branch information
TRMSC authored Mar 4, 2022
2 parents a1c70ab + 73fff5e commit 22f4380
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Backup your calendars and adressbook directly from the cloud!


Thanks to [Tiktaktux-Wiki](https://www.tiktaktux.de/doku.php?id=linux:caldav_und_carddav_backup_erstellen) for the important base. ✨
Thanks to [Tiktaktux-Wiki](https://www.tiktaktux.de/doku.php?id=linux:caldav_und_carddav_backup_erstellen) and [Henry Koch](https://www.henrykoch.de/de/python-loeschen-der-aeltesten-files-in-einem-verzeichnis-nur-die-neuesten-x-bleiben-zurueck) for important bases. ✨

Further a big thanks to [Cermit](https://twitter.com/Cermit3273?s=20&t=quwG6m5sDXRab5OmeCgPoQ) for the great help to make my first python project! 🎉

Expand Down
5 changes: 4 additions & 1 deletion cloud-backup-data.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Cloud Backup v.1.0 - Copyright (C) 2022, TRMSC - https://trmsc1.wordpress.com/
# Cloud Backup v.1.1 - Copyright (C) 2022, TRMSC - https://trmsc1.wordpress.com/
# GNU General Public Licence 3.0 - http://www.gnu.de/documents/gpl-3.0.en.html

# PUT IN YOUR DATA NEEDED FOR THE BACKUP PROGRESS

# Change the backup directory or use the default:
cloud-backup-storage/

# Number of subdirectories for backup days that should be stored:
2

# Add your accessdata:
YOURUSERNAME
YOURPASSWORD
Expand Down
61 changes: 46 additions & 15 deletions cloud-backup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cloud Backup v.1.0.1 - Copyright (C) 2022, TRMSC - https://trmsc1.wordpress.com/
# Cloud Backup v.1.1 - Copyright (C) 2022, TRMSC - https://trmsc1.wordpress.com/
# GNU General Public Licence 3.0 - http://www.gnu.de/documents/gpl-3.0.en.html

# Prepare the backdata.txt and put it in the same directory like this script.
Expand All @@ -7,10 +7,11 @@
import requests
import datetime
import os
import shutil

print ("Cloud Backup v.1.0.1")
print ("Cloud Backup v.1.1")
print ("Feel free to visit trmsc1.wordpress.com")
print ("\nChecking data...")
print ("\nCheck data...")

# Check date
folderdate = datetime.datetime.now().strftime("%Y-%m-%d")
Expand All @@ -20,27 +21,49 @@
# Check data
with open("cloud-backup-data.txt", "r") as backdata:
content = backdata.readlines ()
backupdir = content[6]
backupdir = backupdir + folderdate + "/"
path = content[6]
path = path.replace('\n', "")
backupdir = path + folderdate + "/"
backupdir = backupdir.replace('\n', "")
print ("Backup directory is " + backupdir + "\n")
user = content[9]
print ("Backup directory is " + backupdir)
maintain = content[9]
maintain = maintain.replace('\n', "")
print (maintain + " older subdirectories will be stored\n")
maintain = int(maintain)
user = content[12]
user = user.replace('\n', "")
passwd = content[10]
passwd = content[13]
passwd = passwd.replace('\n', "")
urlvcf = content[13] + "?export"
urlvcf = content[16] + "?export"
urlvcf = urlvcf.replace('\n', "")
url = content[16]
calendarlist = content[20].replace('\n', "").split(",")
url = content[19]
calendarlist = content[23].replace('\n', "").split(",")

# Check and create directory
# Check and create storage directory
if not os.path.exists(path):
os.makedirs(path)

# Check older versions
print ("\nCheck older versions for cleaning...")
if os.path.exists(backupdir):
maintain = maintain + 1
def sorted_ls(path):
mtime = lambda f: os.stat(os.path.join(path, f)).st_ctime
return list(sorted(os.listdir(path), key = mtime))
del_list = sorted_ls(path)[0:(len(sorted_ls(path)) - maintain)]
print (del_list)

# Check and create todays subfolder
if not os.path.exists(backupdir):
os.makedirs(backupdir)

# Start backup progress
print ("\nStart backup progress...")

# Calendar download
for i in calendarlist:
filename = backupdir + filedate + "-" + i + ".ics"
print ("Downloading " + filename + "...")
print ("Downloading " + filename)
calurl = url + i + "/?export"
calurl = calurl.replace('\n', "")
r = requests.get(calurl, auth = (user, passwd), allow_redirects = True)
Expand All @@ -49,10 +72,18 @@

# Adressbook download
filename = backupdir + filedate + "-adressbook.vcf"
print ("Downloading " + filename + "...")
print ("Downloading " + filename)
r = requests.get(urlvcf, auth=(user, passwd),allow_redirects=True)
with open(filename, 'wb') as a:
a.write(r.content)

# Remove older versions
print ("\nClean older versions...")
if del_list == []:
print ("[]")
for dfile in del_list:
print ("Removing " + path + dfile)
shutil.rmtree(path + dfile)

# Finish
print ("Backup finished")
print ("\nBackup finished")

0 comments on commit 22f4380

Please sign in to comment.