Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:55:13+00:00 2026-06-17T08:55:13+00:00

I have a script that i use to push files back to my home

  • 0

I have a script that i use to push files back to my home PC using rsync. File names successfully pushed are added to a sqlite database so they don’t get pushed again ( since i only want 1 way mirror ). Anyhow, the problem that i have is that although the script recursively goes down the source path and push files based on a defined extension, the files go down the same destination root directory.

What i am trying to is to have the destination folder structure the same as the source.

I think i have to do add something to the destDir path, but not exactly sure what:

for root, dirs, files in os.walk(sourceDir):
   for file in files:
     //If some filtering criteria
     print("Syncing new file: "+file)
     cmd=["rsync"]
     cmd.append(os.path.join(root, file))
     cmd.append(destDir+ "/")
     p=subprocess.Popen(cmd,shell=False)
 if p.wait()==0:
  rememberFile(file)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:55:14+00:00Added an answer on June 17, 2026 at 8:55 am

    I think you should rely on the features of rsync for this as much as possible, rather than trying to reimplement it in Python. rsync has been extensively tested and is full-featured. They’ve fixed all of the bugs that you’re encountering. For instance, in your original code snippet, you need to reconstruct the full path of your file (instead of just the filename) and add that to your destDir.

    But before you keep debugging that, consider this alternative. Instead of a sql db, why not keep all of the files that you have pushed in a plain text file? Let’s say it’s called exclude_list.txt. Then your one-liner rsync command is:

    rsync -r --exclude-from 'exclude_list.txt' src dst
    

    The -r switch will cause it to traverse the file tree automatically. See topic #6 on this page for more details on this syntax.

    Now you only need your Python script to maintain exclude_list.txt. I can think of two options:

    • Capture the output of rsync with the -v option to list the filenames that were moved, parse them, and append to exclude_list.txt. I think this is the most elegant solution. You can probably do it in just a few lines.
    • Use the script you already have to traverse the tree and add all of the files to exclude_list.txt, but remove all of the individual rsync calls. Then call rsync once at the end, as above.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files. location.php, that outputs this: [[javascript],[PHP]] and in another file: <script
I have a script that makes use of a package (PKG_MY_PACKAGE). I will change
I have a Python script that makes use of 'Print' for printing to stdout.
I have a script like that genhash --use-ssl -s $IP -p 443 --url $URL
I have a script that executes database queries, and I use semi-colons + new
In php I have a script, that I use mod_rewrite to redirect all calls
I have a Perl script I wrote for my own personal use that fetches
I have a file called Strings.h, that I use to localize an app I
I have been writing a script to add untracked files using git add .
I'm running MAMP locally. I have a php script that I use to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.