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 6185551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:44:02+00:00 2026-05-24T01:44:02+00:00

Below is a script I am using to test a problem. Running an rsync

  • 0

Below is a script I am using to test a problem.

Running an rsync command via subprocess.check_call does not work in excluding files obtained from an exclude variable.

I am printing the result of the command from Python, editing it and then running it in a bash shell directly as a comparison and it fails to exclude my exclusions when using Python.

#!/usr/bin/env python3.1

import subprocess

exclude = 'exclude_me_dir, exclude_me_file.txt'
source_path = '/tmp/source'
path_to_backup_file_name = '/tmp/destination'
engine_options = '-axh --delete --delete-excluded'

def rsync_backup(source_path, path_to_backup_file_name, exclude, engine_options):
    exclusions = ['--exclude="%s"' % x.strip() for x in exclude.split(',')]
    rsync_command = ['rsync'] + exclusions + engine_options.split() + [source_path + '/', path_to_backup_file_name]
    print(rsync_command)
    return subprocess.check_call(rsync_command)


rsync_backup(source_path, path_to_backup_file_name, exclude, engine_options)

This is the output of the Python script and running the rsync command directly.

> pwd
/root
> ls /tmp/source/
exclude_me_dir/  exclude_me_file.txt  file1.txt  folder1/
> /tmp/rsynctest.py
['rsync', '--exclude="exclude_me_dir"', '--exclude="exclude_me_file.txt"', '-axh', '--delete', '--delete-excluded', '/tmp/source/', '/tmp/destination']
> ls /tmp/destination/
exclude_me_dir/  exclude_me_file.txt  file1.txt  folder1/
> rsync --exclude="exclude_me_dir" --exclude="exclude_me_file.txt" -axh --delete --delete-excluded /tmp/source/ /tmp/destination
> ls /tmp/destination/
file1.txt  folder1/

N.B. As I was about to post this I discovered the problem appears to be the double quotes in ‘–exclude=”file”‘ as if I remove them it works. I tried escaping them like so ‘–exclude=\”file\”‘. but this does not work either. I require the double quotes for occasions when a space occurs in a file name or directory.

What am I missing?

  • 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-05-24T01:44:03+00:00Added an answer on May 24, 2026 at 1:44 am

    Yes the double quotes are the problem, don’t escape them, just drop them.

    They are just required on the shell to hinder the shell from expanding.

    Moreover: If you escape them the way you’ve shown, they are only escaped on the python level where it makes no sense, because double quotes are automatically escaped inside of single quotes

    In [2]: '\"foo\"'
    Out[2]: u'"foo"'
    

    it should be

    In [3]: '\\"foo\\"'
    Out[3]: u'\\"foo\\"'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small script which im using to test PHP mail(), as below:
I have tested the below script on a demo page which is not using
The script below worked on my Mac OS X. I'm now using Ubuntu OS,
I want to enable auto update script in flex3. i am using below code
The script below, test.php, is intended to be placed in a specific directory of
I am getting below error when running a target of ANT script. Error message
I'm using the script below to send an email to myself, the script runs
I have recently encountered a problem in IE, using the jQuery UI datepicker script:
I tried to install python below way. But this did not work. This take
Using Javascript I'm trying to test whether or not a DIV with the id

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.