Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Oh apparently it's SQlite: https://www.lightroomqueen.com/community/tags/sqlite/
- I don't have lightroom so I've guessed a few things.
- So try this one:
- ```
- pip install sqlite3 pandas borgbackup
- ```
- ```
- import os
- import sys
- import sqlite3
- import pandas as pd
- from subprocess import call
- def get_rated_images(catalog_file):
- conn = sqlite3.connect(catalog_file)
- cursor = conn.cursor()
- query = '''
- SELECT
- A.name AS Folder_Name,
- B.baseName || '.' || C.value AS File_Name,
- D.value AS Rating,
- A.absolutePath || A.name || '/' || B.baseName || '.' || C.value AS File_Path
- FROM
- AgLibraryFolder A
- JOIN AgLibraryFile B ON A.id_local = B.folder
- JOIN AgLibraryIPTC C ON B.id_local = C.image
- JOIN Adobe_images D ON B.id_local = D.id_local
- WHERE
- C.fieldName = 'XMP:MetadataDate'
- AND D.rating IN (4, 5)
- AND B.fileFormat IN ('RAW', 'CR2', 'NEF', 'DNG', 'ARW')
- '''
- cursor.execute(query)
- rated_images = cursor.fetchall()
- conn.close()
- return rated_images
- def main():
- if len(sys.argv) != 4:
- print("Usage: python lightroom_borgbackup.py <lightroom_catalog_path> <repo_path> <backup_name>")
- return
- catalog_path = sys.argv[1]
- repo_path = sys.argv[2]
- backup_name = sys.argv[3]
- catalog_file = os.path.join(catalog_path, 'Lightroom Catalog.lrcat')
- if not os.path.exists(catalog_file):
- print("Lightroom Catalog not found. Please check the path.")
- return
- rated_images = get_rated_images(catalog_file)
- files_to_backup = [image[3] for image in rated_images]
- # Create a temporary file with the list of files
- with open('files_to_backup.txt', 'w') as f:
- f.write('\n'.join(files_to_backup))
- # Invoke borgbackup
- call(['borg', 'create', '--files-from', 'files_to_backup.txt', f'{repo_path}::{backup_name}', '.'])
- # Remove the temporary file
- os.remove('files_to_backup.txt')
- if __name__ == "__main__":
- main()
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement