Compare commits

..
115 Commits
Author SHA1 Message Date
Fuxino 166c9dbc47 Bump version to 4.3.0 2026-10-08 20:47:04 +02:00
Fuxino 28d1b0d0d0 Add a timeout to the SSH connection
paramiko's connect had no timeout, so a server that doesn't answer
made the program hang until the OS gave up (about 2 minutes). Give up
after 15 seconds and exit with code 5.
2026-10-08 20:45:07 +02:00
Fuxino cd80c941ad Treat empty SSH settings in the config as not set
The example config has empty remote_sudo and numeric_ids values, which
made getboolean fail with "Bad configuration file" if the [server]
section was uncommented, and an empty ssh_keyfile was used as the key
path. Treat empty values as false or not set, and show false in the
example config.
2026-10-08 20:42:05 +02:00
Fuxino 29958896a2 Always close the SSH connection
The connection was only closed at the end of a backup that ran to
completion, not on early returns (e.g. missing output folder or no
inputs) or exceptions, and a client that failed to log in was left
open. Close it in all cases, and remove the unused _password field.
2026-10-08 20:40:41 +02:00
Fuxino d815b0832a Only count directories when removing old local backups
Old backups were listed with os.listdir, so a stray file or symlink
in the backup folder counted as a backup: depending on its name,
rmtree crashed on it or one backup too many was removed. An
unreadable backup folder also crashed with PermissionError. Count
only directories, and log an error if the folder can't be read.
2026-10-08 20:38:20 +02:00
Fuxino e6ac9e6cab Fix remote removal of old backups deleting the wrong folders
Old backups on the server were listed with ls, which also lists files
and prints nothing on errors. A stray file made one backup too many
get removed, and an empty or unreadable backup folder was counted as
one backup with an empty name, which made rm -r delete the whole
simple_backup folder. List only directories with find, and don't
remove anything if listing fails.
2026-10-08 20:36:55 +02:00
Fuxino 9298f4232c Fix crash on empty answer to the unknown host key prompt
An empty answer raised IndexError, and running without a terminal
(e.g. from cron) raised EOFError. Treat both as "no", and log why the
connection was aborted.
2026-10-08 20:34:02 +02:00
Fuxino 1dca989310 Fail if only one of SSH host and SSH user is set
Remote backup needs both, but if only one was set the program silently
ran a local backup instead, and a missing ssh_user in the config also
dropped ssh_host. Exit with an error (code 6) instead.
2026-10-08 20:31:39 +02:00
Fuxino 9a68a8660d Resolve the remote output path on the server
The output path was made absolute with os.path.abspath and '~' was
expanded to the local home, so relative paths and '~' pointed to the
wrong folder on the server. Resolve the path on the server instead,
where '~' and relative paths refer to the remote user's home, and
document it.
2026-10-08 20:29:21 +02:00
Fuxino 73de4f8d25 Build the rsync command as an argument list
The rsync command was built as a string and split with shlex.split,
so paths containing quotes broke it, and the key file path in the -e
command was split on spaces. Pass each path as its own argument, and
quote the key file and user name inside the -e command, which rsync
splits itself.
2026-10-08 20:24:53 +02:00
Fuxino baf5b07d23 Quote paths in commands run on the SSH server
Remote commands were built with f-strings, with paths either unquoted
or in double quotes. Paths with spaces broke ls and find, and $ or
backticks in a path were expanded by the server's shell. Quote every
path with shlex.quote.
2026-10-08 20:22:35 +02:00
Fuxino 8b30fefed3 Don't disable host key checking for rsync's ssh
rsync's ssh command used StrictHostKeyChecking=no, so it connected
even if the server's host key had changed. Use accept-new instead:
unknown hosts are still added automatically, but a changed key for a
known host makes the connection fail.
2026-10-08 20:19:46 +02:00
Fuxino 2a5562d1a9 Pass the SSH key file to rsync also when not running as root
The key file given with --keyfile was only passed to rsync's ssh
command when running as root, so as a normal user rsync ignored it
and fell back to the default keys or the agent.
2026-10-08 20:17:29 +02:00
Fuxino 7091118663 Handle SSH connection errors instead of crashing
An unknown hostname, a refused connection or an unreachable server
raise OSError (socket.gaierror, NoValidConnectionsError), which
paramiko.SSHException doesn't cover, so the program crashed with a
traceback. Log the error and exit with code 5 instead.
2026-10-08 20:14:39 +02:00
Fuxino 3113e182c7 Treat rsync return code 24 as success
Code 24 (source files vanished during the transfer) already counted as
success when deciding whether to remove old backups, but the program
still exited with 4 and reported errors. Exit with 0 and report the
backup as completed, logging only a warning, so both checks agree.
2026-10-08 20:12:29 +02:00
Fuxino 8fc3c42a5e Fix exit code and success check for remote backups
The remote branch of run() returned None, so the program always exited
with 0, and it decided whether the backup worked by checking that the
backup folder existed on the server, ignoring rsync's return code.
Use the same return code check for local and remote backups.
2026-10-08 20:10:52 +02:00
Fuxino 0671f86579 Fix SSH key loading for ed25519 and ECDSA keys
Unencrypted ed25519 and ECDSA keys crashed with an uncaught
SSHException, and the DSA fallback raised NameError since paramiko 4
removed DSSKey. Load the key with paramiko.PKey.from_path instead,
ask for the passphrase only when the key is encrypted, and log an
error instead of crashing when the key can't be loaded.

Require paramiko >= 3.2 for PKey.from_path.
2026-10-08 20:06:57 +02:00
Fuxino 2f207efcf9 Update PKGBUILD 2026-10-08 18:25:08 +02:00
Fuxino 3cbca8e4d8 Bump version to 4.2.0 2026-10-08 18:23:03 +02:00
Fuxino 54880651be Fix outdated and wrong information in README
Use git.shouldnt.work as the clone URL, don't install wheel for
building, as setuptools no longer needs it, list paramiko among the
optional dependencies, and use the correct names of the remote
backup options (--ssh-user, --ssh-host).
2026-10-08 18:19:35 +02:00
Fuxino 793a30fad8 Remove unused python-dotenv dependency
load_dotenv() was called, but no setting was ever read from a .env
file. Drop it from the code, pyproject.toml, PKGBUILD and README.
2026-10-08 18:15:07 +02:00
Fuxino 871dd0f49a Warn if a backup fails after old backups were removed
With --remove-before-backup, a failed backup leaves only the kept
backups, or none with keep=0. Log an error and send a notification
in that case, and document it in the man page.
2026-10-08 18:13:13 +02:00
Fuxino 30e4416f8f Look for the last backup after removing old ones
With --remove-before-backup, the last backup was selected for
--link-dest before old backups were removed, so with keep=0 rsync
was given a directory that no longer existed.
2026-10-08 18:11:25 +02:00
Fuxino d0f888cbb4 Always use --mkpath and --ignore-missing-args with rsync
With --rsync-options, only -r and -v were kept, so the first backup
failed because the simple_backup directory did not exist yet, and a
missing input made rsync fail. Use these options in any case.
2026-10-08 18:08:28 +02:00
Fuxino 7ef29cf551 Report invalid config files instead of crashing
Invalid values (e.g. an empty or non-numeric 'keep') and syntax
errors in the config file raised uncaught exceptions. Catch them
and exit with code 6, including the reason in the error message.
2026-10-08 18:06:33 +02:00
Fuxino 4f5499eba9 Allow '%' in config file values
ConfigParser interpolation treats '%' as special, so a path or
pattern containing it crashed the program. Disable interpolation,
which is not used by the config file.
2026-10-08 18:05:11 +02:00
Fuxino fc165fccbf Only expand '~' at the start of config paths
Every '~' in inputs and backup_dir was replaced with '~user', so
paths like 'notes~' or '~otheruser' did not match. Expand only a
leading '~' or '~/'.
2026-10-08 18:04:25 +02:00
Fuxino d79ea56c0f Ignore whitespace around comma-separated config values
'inputs=/a, /b' was read as '/a' and ' /b', so /b was skipped, and
excluded patterns with spaces around them never matched. Strip
whitespace from each value, and ignore empty exclude entries.
2026-10-08 18:03:18 +02:00
Fuxino 5189910131 Don't use ':' in backup directory names
':' is not allowed on FAT/exFAT filesystems, so backups to such
drives failed. Use '%Y-%m-%d_%H-%M-%S' instead; existing backups
with the old format still sort correctly. Document the limitations
of FAT/exFAT in the man page.
2026-10-08 18:01:07 +02:00
Fuxino 7d4c43f8ff Always remove temp files and close their descriptors
The inputs temp file was left behind when no inputs existed, and
both temp files if rsync failed to start. The descriptors returned
by mkstemp were also never closed. Remove the temp files when run()
exits in any way, and write them through the mkstemp descriptors.
2026-10-08 17:58:32 +02:00
Fuxino ac7e6ec21b Don't print tracebacks when desktop notifications fail
Without dbus-python, or without a session bus (e.g. when running
from a timer), each notification printed a traceback. Skip
notifications if dbus is not installed, and log a single warning
if sending one fails. Remove the now unneeded NameError handling
around _notify calls.
2026-10-08 17:55:57 +02:00
Fuxino 578d992a19 Only turn warnings into errors where needed
warnings.filterwarnings('error') applied to the whole program, so
any warning raised by a library (e.g. a DeprecationWarning) would
crash it. Limit it to the ssh connection (unknown host key) and
the password prompt (no terminal available).
2026-10-08 17:50:47 +02:00
Fuxino e2d8897a45 Fix crash on Python < 3.14 when paramiko is not installed
The return annotation of _ssh_connect referenced paramiko, which
Python < 3.14 evaluates at class definition, raising NameError when
paramiko (an optional dependency) is missing. Postpone evaluation
of annotations, and mark the return type as Optional.
2026-10-08 17:47:02 +02:00
Fuxino dadc4b0265 Resolve default config path after the user is known
The default config path was computed before -u was parsed, so
running as root without sudo/doas used '~None/...' even when the
user was given with -u. Expand '~' only after the user is detected.
2026-10-08 17:45:02 +02:00
Fuxino 7e7d11c520 Detect the invoking user when running with doas
User detection only checked SUDO_USER, so with doas the user's
config file was not found unless -u was given. Fall back to
DOAS_USER, as already done for notifications.
2026-10-08 17:43:28 +02:00
Fuxino 22e0556b50 Document that old backups are kept if rsync fails 2026-10-08 17:41:17 +02:00
Fuxino 2b91178e94 Don't remove old backups if rsync fails
If rsync returns an error, the new backup may be incomplete. Keep
the old backups in that case, except for return code 24 (vanished
source files), which is expected when backing up a live system.
2026-10-08 17:38:34 +02:00
Fuxino 2c2649113d Fix relative input paths being silently skipped
rsync reads --files-from entries relative to the source directory
('/'), so relative inputs pointed to the wrong path and were ignored
due to --ignore-missing-args. Convert inputs to absolute paths.
2026-10-08 17:35:35 +02:00
Fuxino 0f4a100ac7 Move package metadata from setup.cfg to pyproject.toml
Drop python-wheel from PKGBUILD makedepends, as setuptools
builds wheels on its own.
2026-10-08 17:29:40 +02:00
Fuxino 60d83151dc Update PKGBUILD 2026-10-03 21:07:16 +02:00
Fuxino 47aec456be Fix notifications when using doas 2026-10-03 21:04:17 +02:00
Fuxino c715188973 Fix code with autopep8 2025-03-30 15:02:50 +02:00
Fuxino 57613649c2 Add missing type hints 2025-03-30 15:02:04 +02:00
Fuxino 67dbb49a67 Update PKGBUILD 2025-03-30 14:53:53 +02:00
Fuxino e62a668f3e Update metadata 2025-03-30 14:39:59 +02:00
Fuxino bd8934d57f Update version tag 2025-03-30 14:38:56 +02:00
Fuxino 96fe3c7813 Update man page 2025-03-30 14:38:29 +02:00
Fuxino 9fdb959540 Improve handling of user detection failure 2025-03-30 14:37:30 +02:00
Fuxino eb889beee7 Add Python 3.13 to setup.cfg 2025-03-30 12:16:04 +02:00
Fuxino 2a37eb4172 Add PKGBUILD 2024-11-13 19:38:12 +01:00
Fuxino 45a07205a1 Add type hints plus minor code fixes 2024-09-28 09:47:33 +02:00
Fuxino 9390cd2de8 Allow removing remote old backups with sudo if possible
If allowed by the remote server, try using sudo to remove
old backups (rm needs to be allowed in sudoers to run
without password)
2023-10-15 15:39:06 +02:00
Fuxino 77661c0964 Handle getpass exception 2023-07-16 08:22:51 +02:00
Fuxino e3a970217f Improve logging 2023-06-25 11:49:02 +02:00
Fuxino 8968fcd1a8 Fix parsing option bug 2023-06-25 10:12:07 +02:00
Fuxino 35b87c859e Add --user arg 2023-06-20 19:22:22 +02:00
Fuxino f3d5ebd276 Merge branch 'development' 2023-06-20 17:36:40 +02:00
Fuxino fb726a80ab Fix bug
Remove forgotten test code -.-
2023-06-20 17:36:12 +02:00
Fuxino 4701ee0b05 Fix typo 2023-06-19 16:00:21 +02:00
Fuxino dd779d242b Fix crash when config file missing 2023-06-18 22:58:53 +02:00
Fuxino 22a3e8d60f Make paramiko optional 2023-06-18 22:53:29 +02:00
Fuxino a26182cedd Update version number 2023-06-16 19:16:47 +02:00
Fuxino 5b3558c282 Merge branch 'development' 2023-06-16 19:15:44 +02:00
Fuxino 4e6adf3c56 Use dict for config options 2023-06-16 17:42:13 +02:00
Fuxino ffed2dec90 Add numeric-ids option for rsync 2023-06-16 16:18:12 +02:00
Fuxino 169f824d83 Improve documentation 2023-06-15 23:15:00 +02:00
Fuxino f77ff2d24f Allow running remote rsync as sudo 2023-06-15 23:12:19 +02:00
Fuxino ffe2b69c99 Fix error in man page 2023-06-15 22:12:38 +02:00
Fuxino 82b0ea88fa Merge branch 'master' into development 2023-06-15 22:10:19 +02:00
Fuxino 970d3dde1e Add manual selection of rsync options 2023-06-15 21:30:43 +02:00
Fuxino 4d23bde906 Check that inputs from command line exist
Check that the inputs specified on the command line (i.e. with the
option '-i' or '--input') exist and print a warning when they don't.
If no valid inputs are found, exit.
2023-06-15 18:44:22 +02:00
Fuxino ff70358496 Version bump 2023-06-15 17:38:00 +02:00
Fuxino 6f1e91e2cd Add more return codes 2023-06-15 17:14:17 +02:00
Fuxino b3fee0d022 Add some meaningful return codes 2023-06-15 16:58:56 +02:00
Fuxino d63eb8f771 Improve handling of missing inputs 2023-06-15 15:34:00 +02:00
Fuxino f95cd86cdc Check backup folder for remote backup
Check that the backup folder exists at the end of the backup when
performing backup over ssh
2023-06-15 11:48:23 +02:00
Fuxino f37cd89b4e Fix parsing of old config file 2023-06-15 09:30:59 +02:00
Fuxino d1b429d37a Merge branch 'master' into development 2023-06-04 16:53:22 +02:00
Fuxino 56df958c5b Add expansion of params in config file
Allow using wildcards (i.e. * to match any character and ~ to match the
user's home directory) in inputs and ouput variables in config file
2023-06-04 12:09:30 +02:00
Fuxino d6d9fbf6e4 Add no-syslog option 2023-06-04 10:16:50 +02:00
Fuxino cee4d13837 Fix bug
Fix crash when attempting to close a non-existent paramiko
SSH connection
2023-06-03 16:14:36 +02:00
Fuxino 252617e4f2 Fix old backups counting 2023-06-03 16:09:34 +02:00
Fuxino 809545b172 Explicitly close paramiko connection 2023-06-03 15:56:24 +02:00
Fuxino b34627fe58 Improve readability 2023-06-03 15:44:31 +02:00
Fuxino cd558e8608 Merge branch 'nolink' into development 2023-06-02 20:12:53 +02:00
Fuxino ffbf8ece91 Remove last_backup link 2023-06-02 19:38:28 +02:00
Fuxino 78760bdda3 Merge branch 'master' into development 2023-06-02 18:38:54 +02:00
Fuxino 6c07c147ae Version bump 2023-06-02 17:04:53 +02:00
Fuxino 5ddd374350 Fix notification bug
Correctly handle exception when trying to display notification if
dbus-python is not available
2023-06-02 17:01:37 +02:00
Fuxino 3d3fbbcbd9 Add password authentication for SSH 2023-06-02 00:09:14 +02:00
Fuxino 4f3d83f458 Update manpage 2023-06-01 22:18:32 +02:00
Fuxino d48eaabbd3 Merge branch 'master' into development 2023-06-01 17:47:44 +02:00
Fuxino 525f381094 Remove PKGBUILD
Removed PKGBUILD since the packages is available in the AUR. Added
a note about AUR in README.md
2023-06-01 17:23:58 +02:00
Fuxino e1ba388296 Update version 2023-06-01 17:18:42 +02:00
Fuxino e84cf81b13 Add man page 2023-06-01 17:08:31 +02:00
Fuxino 7664fa1b33 Update README.md 2023-05-31 22:12:59 +02:00
Fuxino 98cb7f5822 Fix ssh authentication when running with sudo 2023-05-31 20:39:03 +02:00
Fuxino b957200deb Change missing hostkey policy 2023-05-31 19:30:31 +02:00
Fuxino 9e90d620e6 Merge branch 'master' into development 2023-05-31 19:21:11 +02:00
Fuxino 06620a4dba Fix bug when exclude pattern is None 2023-05-31 19:07:50 +02:00
Fuxino ba97b25e25 Add docstrings 2023-05-29 23:10:29 +02:00
Fuxino 335ad348e5 Update README.md 2023-05-29 21:56:58 +02:00
Fuxino df18e383ed Update dependencies 2023-05-29 19:02:05 +02:00
Fuxino 7eb71bc924 Add rsync compress option 2023-05-29 18:33:02 +02:00
Fuxino c25ef52393 Implement remove old backups from server 2023-05-29 17:57:12 +02:00
Fuxino 24a59bde2d Use ssh agent if available 2023-05-29 00:09:54 +02:00
Fuxino 88e6a9a141 Add incremental backups on server 2023-05-28 23:19:08 +02:00
Fuxino 38c090e257 Add basic remote backup functionality 2023-05-28 21:30:40 +02:00
Fuxino 0dd7b887f7 Update PKGBUILD to use release version 2023-05-28 11:07:03 +02:00
Fuxino 7684bc43b0 Add desktop notifications 2023-05-25 23:44:59 +02:00
Fuxino a07fce1b6c Version bump 2023-05-25 19:01:50 +02:00
Fuxino 11c1ab0952 Add options to remove old backups before copying files 2023-05-25 19:01:19 +02:00
Fuxino a42ade4f2b Version bump 2023-05-25 17:27:04 +02:00
Fuxino c6432c1350 Check rsync return code 2023-05-25 17:20:32 +02:00
Fuxino fa1d8f410e Remove old last_backup link after copying files 2023-05-25 17:10:38 +02:00
11 changed files with 1216 additions and 254 deletions
+1
View File
@@ -1,2 +1,3 @@
.idea/ .idea/
__pycache__/
test/ test/
+21 -30
View File
@@ -1,47 +1,38 @@
# PKGBUILD # PKGBUILD
# Maintainer: Daniele Fucini <dfucini@gmail.com> # Maintainer: Daniele Fucini <dfucini [at] gmail [dot] com>
pkgname=simple_backup pkgname=simple_backup
pkgver=3.1.2.r1.ga4c4b88
pkgrel=1
pkgdesc='Simple backup script that uses rsync to copy files' pkgdesc='Simple backup script that uses rsync to copy files'
pkgver=4.2.0
pkgrel=1
url="https://git.shouldnt.work/fuxino/${pkgname}"
arch=('any') arch=('any')
url="https://github.com/Fuxino/simple_backup.git" license=('GPL-3.0-or-later')
license=('GPL3')
makedepends=('git' makedepends=('git'
'python-setuptools' 'python-setuptools'
'python-build' 'python-build'
'python-installer' 'python-installer')
'python-wheel') depends=('python>=3.10'
depends=('python' 'rsync')
'rsync' optdepends=('python-systemd: use systemd log'
'python-dotenv') 'python-dbus: for desktop notifications'
optdepends=('python-systemd: use systemd log') 'python-paramiko: for remote backup through ssh')
install=${pkgname}.install conflicts=('simple_backup-git')
source=(git+https://github.com/Fuxino/${pkgname}.git) source=(git+${url}?signed#tag=${pkgver})
sha256sums=('SKIP') validpgpkeys=('7E12BC1FF3B6EDB2CD8053EB981A2B2A3BBF5514')
sha256sums=('6c674f7981e3e5222594bdb735d4fb02ca2fcc829de57ea8f92ce71e679853f9')
pkgver()
{
cd ${pkgname}
git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}
prepare()
{
git -C ${srcdir}/${pkgname} clean -dfx
}
build() build()
{ {
cd ${srcdir}/${pkgname} cd ${srcdir}/${pkgname}
python -m build --wheel --no-isolation python -m build --wheel --no-isolation
} }
package() package()
{ {
cd ${srcdir}/${pkgname} cd ${srcdir}/${pkgname}
python -m installer --destdir=${pkgdir} dist/*.whl python -m installer --destdir=${pkgdir} dist/*.whl
install -Dm644 ${srcdir}/${pkgname}/${pkgname}.conf ${pkgdir}/etc/${pkgname}/${pkgname}.conf install -Dm644 ${pkgname}/${pkgname}.conf ${pkgdir}/usr/share/doc/${pkgname}/${pkgname}.conf
install -Dm644 man/${pkgname}.1 ${pkgdir}/usr/share/man/man1/${pkgname}.1
} }
+34 -7
View File
@@ -20,28 +20,55 @@ The script uses rsync to actually run the backup, so you will have to install it
sudo pacman -Syu rsync sudo pacman -Syu rsync
``` ```
Optional dependencies are systemd-python to enable using systemd journal for logging, dbus-python for desktop notifications, and paramiko for remote backup.
## Install ## Install
To install the program, first clone the repository: To install the program, first clone the repository:
```bash ```bash
git clone https://github.com/Fuxino/simple_backup.git git clone https://git.shouldnt.work/fuxino/simple_backup.git
``` ```
Install tools required to build and install the package: Then install the tools required to build the package:
```bash ```bash
pip install --upgrade build installer wheel pip install --upgrade build
``` ```
Then run: Finally, run:
```bash ```bash
cd simple_backup cd simple_backup
python -m build --wheel python -m build --wheel
python -m installer dist/*.whl python -m pip install dist/*.whl
``` ```
For Arch Linux, a PKGBUILD that automates this process is provided. For Arch Linux and Arch-based distros, two packages are available in the AUR (aur.archlinux.org):
- **simple_backup** for the release version
- **simple_backup-git** for the git version
After installing, copy simple_backup.conf (if you used the PKGBUILD on Arch, it will be in /etc/simple_backup/) to $HOME/.config/simple_backup and edit is as needed. ## Old backups
The number of old backups to keep can be set with the --keep (or -k) argument (or in the configuration file).
Old backups are only removed if rsync completes successfully, so that they are not deleted when the new backup may be incomplete.
The only rsync error that is ignored is return code 24 (source files vanished during the transfer), which is common when backing up a live system.
## Remote backup
> **Warning**
> This feature is experimental
It's possible to use a remote server as destination for the backup. Just use the --ssh-user and --ssh-host arguments (or set them in the configuration file).
For this to work, rsync must be installed on the server too.
### Server authentication
The best way to handle the authentication is to have an ssh agent running on your system, otherwise if a passphrase is necessary to unlock the ssh key, it will be necessary to enter it more than once.
If needed, it's possible to specify the ssh key location with the --keyfile argument or in the configuration file.
To be able to connect to the user's ssh agent when running simple_backup with sudo, make sure to preserve the SSH_AUTH_SOCK environment variable. For example:
```bash
sudo --preserve-env=SSH_AUTH_SOCK -s simple_backup [options]
```
or by editing the sudoers file.
If SSH key authentication is not available, password authentication will be used instead.
Check the man page for more details.
+216
View File
@@ -0,0 +1,216 @@
.TH SIMPLE_BACKUP 1 2026-10-08 SIMPLE_BACKUP 4.3.0
.SH NAME
simple_backup \- Backup files and folders using rsync
.SH SYNOPSIS
.B simple_backup
\-h, \-\-help
.PD 0
.P
.PD
.B simple_backup
[\-c, \-\-config FILE]
[\-i, \-\-input INPUT [INPUT...]]
[\-o, \-\-output DIR]
.PD 0
.P
.PD
.RS 14 [\-e, \-\-exclude FILE|DIR|PATTERN [FILE|...]]
[\-k, \-\-keep N]
[\-\-ssh\-host HOSTNAME]
[\-\-ssh\-user USERNAME]
[\-\-keyfile FILE]
.PD 0
.P
.PD
[\-s, \-\-checksum]
[\-z, \-\-compress]
[\-\-remove\-before\-backup]
.RE
.SH DESCRIPTION
.B simple_backup
is a python script for performing backup of files and folders.
.P
It uses rsync to copy the files to the specified location. Parameters for the backup such as
input files/directories, output location and files or folders to exclude can be specified
in a configuration file (default location $HOME/.config/simple_backup/simple_backup.conf)
or directly on the command line.
.P
Parameters specified on the command line will override those in the configuration file.
.SH OPTIONS
.TP
.B \-h, \-\-help
Print a short help message and exit.
.TP
.B \-c, \-\-config FILE
Specify the configuration file, useful to specify a different one from the default.
.TP
.B \-i, \-\-input INPUT [INPUT...]
Specify the files and directories to backup. Multiple inputs can be specified, just separate
them with a space. If filenames or paths contain spaces, don't forget to escape them,
or to use single or double quotes around them.
.TP
.B \-o, \-\-output DIR
Specify the directory where the files will be copied. The program will automatically
create a subdirectory called \(aqsimple_backup\(aq (if it does not already exist) and
inside this directory the actual backup directory (using the current date and time, for example
\(aq2026\-10\-08_17\-34\-47\(aq).
.RS
.P
Backups are best stored on a Linux filesystem (e.g. ext4 or btrfs). FAT and exFAT filesystems
are supported, but they don\(aqt support hard links, so each backup will be a full copy instead
of only storing files that changed since the previous one. File ownership and permissions are
not preserved either.
.RE
.TP
.B \-e, \-\-exclude FILE|DIR|PATTERN [FILE|...]]
Specify files, directories or patterns to exclude from the backup. Matching files and directories
will not be copied. Multiple elements can be specified, in the same way as for the \-\-input option.
.TP
.B \-k, \-\-keep N
Specify how many old backups (so excluding the current one) will be kept. The default behavior
is to keep them all (same as N=\-1).
Old backups are only removed if rsync completes successfully, to avoid deleting them when the
new backup may be incomplete. rsync return code 24 (source files vanished during the transfer)
is treated as success, while any other error (including return code 23, partial transfer due to error)
will prevent old backups from being removed. This does not apply when using \-\-remove\-before\-backup.
.TP
.B \-u, \-\-user USERNAME
Explicitly specify the user running the backup (in case it is needed for home directory expansion).
.TP
.B \-\-ssh\-host HOSTNAME
Hostname of the server where to copy the files in case of remote backup through SSH.
.TP
.B \-\-ssh\-user USERNAME
Username for connecting to the server in case of remote backup.
.TP
.B \-\-keyfile FILE
Location of the SSH key for server authentication.
.TP
.B \-s, \-\-checksums
Same as rsync option \(aq\-\-checksum\(aq, use checksums instead of mod\-time and size
to skip files.
.TP
.B \-z, \-\-compress
Compress data during transfer (rsync \(aq\-\-compress\(aq option). Useful for remote backup
if saving bandwith is needed.
.TP
.B \-\-remove\-before\-backup
Remove old backups (if necessary) before creating the new backup. Useful to free some space
before performing the backup.
Default behavior is to remove old backups after successfully completing the backup.
Note that if the backup fails after old backups have been removed, only the backups kept
according to \-\-keep will be left, and the new backup may be incomplete. In particular, with
\-\-keep 0 there will be no complete backup available until the next successful one.
.TP
.B \-\-no\-syslog
Don't use systemd journal for logging.
.TP
.B \-\-rsync\-options OPTIONS [OPTION...]
By default, the following rsync options are used:
.RS
.P
\-a \-r \-v \-h \-s \-H \-X
.P
Using \-\-rsync\-options it is possible to manually select which options to use. Supported values are the following:
.P
\-a, \-l, \-p, \-t, \-g, \-o, \-c, \-h, \-D, \-H, \-X, \-s
.P
Options \-r, \-v, \-\-ignore\-missing\-args and \-\-mkpath are used in any case. Note that options must be specified without dash (\-), for example:
.P
.EX
simple_backup \-\-rsync\-options a l p
.EE
.P
Check
.BR rsync (1)
for details about the options.
.RE
.TP
.B \-\-remote\-sudo
Run rsync on the remote server with sudo. This is needed if you want to preserve the owner of the files/folders to be copied (rsync \-\-owner option). For this to work the user used to login to the server obviously need to be allowed to use sudo. In addition, the user need to be able to run rsync with sudo without a password. To do this, /etc/sudoers on the server need to be edited adding a line like this one:
.RS
.P
<username> ALL=NOPASSWD:<path/to/rsync>
.P
To be able to remove old backups generated with \-\-remote\-sudo (see \-\-keep option), also
.BR rm (1)
needs to be allowed to run without password in the same way.
.RE
.TP
.B \-\-numeric\-ids
Use rsync \-\-numeric\-ids option. This causes rsync to use numeric uid/gid instead of trying to map uid/gid names from the local machine to the server.
.SH CONFIGURATION
An example configuration file is provided at \(aq/usr/share/doc/simple_backup/simple_backup.conf\(aq.
Copy it to the default location ($HOME/.config/simple_backup) and edit it as needed.
.SH REMOTE BACKUP
It is possible to choose a directory on a remote server as destination for the backup. The files
are copied by rsync through SSH. Server hostname and username must be specified, either in the
configuration file, or on the command line (\(aq\-\-ssh\-host\(aq and \(aq\-\-ssh\-user\(aq options).
.P
The output directory is a path on the server. A leading \(aq~\(aq and relative paths refer to the
home directory of the user on the server. On the command line, quote \(aq~\(aq so that the local
shell doesn\(aqt expand it, for example:
.P
.EX
simple_backup \-\-ssh\-host server \-\-ssh\-user user \-o \(aq~/backups\(aq
.EE
.SS AUTHENTICATION
For authentication, it is possible to use SSH key or password.
.P
When using SSH key, the best way to connect to the server is to have an SSH agent running.
Otherwise, if the SSH key is encrypted, it will be necessary to enter the passphrase more
than once. It is possible to specify the SSH key to use with the option \(aq\-\-keyfile\(aq,
if necessary.
.P
When running
.B simple_backup
with
.B sudo,
in order to connect to the user\(aqs SSH agent it is necessary to preserve the \(aqSSH_AUTH_SOCK\(aq environment variable, for example:
.P
.EX
sudo --preserve-env=SSH_AUTH_SOCK -s simple_backup [options]
.EE
.P
It is also possible to make this permanent by editing the
.B sudoers
file (see
.BR sudoers (5))
.P
If SSH key authentication is not available, password authentication will be used instead.
Note that in this case
.B sshpass
(if available) will be used to send the password to rsync, to avoid prompting the user for
the password multiple
times. This can pose some security risks, see
.BR sshpass (1)
for details. For this reason, use SSH key authentication if possible.
.SH EXIT STATUS
.TP
.B 0
The backup was completed without errors. This includes rsync return code 24 (some source files
vanished during the transfer), which only logs a warning.
.TP
.B 1
No valid inputs selected for backup.
.TP
.B 2
Backup failed because output directory for storing the backup does not exist.
.TP
.B 3
Permission denied to access the output directory.
.TP
.B 4
rsync error (rsync returned a value other than 0 or 24).
.TP
.B 5
SSH connection failed.
.TP
.B 6
Bad configuration file or options (for example, only one of SSH host and SSH user specified).
.SH SEE ALSO
.BR rsync (1)
.SH AUTHORS
.MT https://git.shouldnt.work/fuxino
Daniele Fucini
.ME
+46 -1
View File
@@ -1,3 +1,48 @@
[build-system] [build-system]
requires = ['setuptools'] requires = ['setuptools>=77']
build-backend = 'setuptools.build_meta' build-backend = 'setuptools.build_meta'
[project]
name = "simple_backup"
dynamic = ["version"]
description = "Simple backup script that uses rsync to copy files"
readme = "README.md"
requires-python = ">=3.10"
license = "GPL-3.0-or-later"
license-files = ["LICENSE"]
authors = [
{ name = "Daniele Fucini", email = "dfucini@gmail.com" }
]
maintainers = [
{ name = "Daniele Fucini", email = "dfucini@gmail.com" }
]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: System :: Archiving :: Backup",
]
[project.optional-dependencies]
JOURNAL = ["systemd-python"]
NOTIFICATIONS = ["dbus-python"]
REMOTE = ["paramiko>=3.2"]
[project.urls]
Homepage = "https://git.shouldnt.work/fuxino/simple_backup"
[project.scripts]
simple_backup = "simple_backup.simple_backup:simple_backup"
[tool.setuptools]
packages = ["simple_backup"]
[tool.setuptools.dynamic]
version = { attr = "simple_backup.__version__" }
-33
View File
@@ -1,33 +0,0 @@
[metadata]
name = simple_backup
version = attr: simple_backup.__version__
description = Simple backup script using rsync
long_description = file: README.md
author = Daniele Fucini
author_email = dfucini@gmail.com
license = GPL3
url = https://github.com/Fuxino/simple_backup
classifiers =
Development Status :: 5 - Production/Stable
Environment :: Console
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Natural Language :: English
Operating System :: POSIX :: Linux
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Topic :: System :: Archiving :: Backup
[options]
packages = simple_backup
python_requires = >=3.7
install_requires =
python-dotenv
systemd-python
[options.entry_points]
console_scripts =
simple_backup = simple_backup.simple_backup:simple_backup
-14
View File
@@ -1,14 +0,0 @@
#Example config file for simple_backup
[default]
#Input directories. Use a comma to separate items
inputs=/home/my_home,/etc
#Output directory
backup_dir=/media/Backup
#Exclude patterns. Use a comma to separate items
exclude=.gvfs,.local/share/gvfs-metadata,.cache,.dbus,.Trash,.local/share/Trash,.macromedia,.adobe,.recently-used,.recently-used.xbel,.thumbnails
#Number of snapshots to keep (use -1 to keep all)
keep=-1
-8
View File
@@ -1,8 +0,0 @@
post_install() {
echo "An example configuration file is found in /etc/simple_backup/simple_backup.conf."
echo "Copy it to ~/config/simple_backup/simple_backup.conf and modify it as needed"
}
post_upgrade() {
post_install
}
+1 -1
View File
@@ -1,3 +1,3 @@
"""Init.""" """Init."""
__version__ = '3.2.2' __version__ = '4.3.0'
+17 -9
View File
@@ -1,14 +1,22 @@
#Example config file for simple_backup # Example config file for simple_backup
[default] [backup]
#Input directories. Use a comma to separate items # Files and directories to backup. Multiple items can be separated using a comma (','). It is possible to use wildcards (i.e. '*' to match multiple characters and '~' for the user's home directory).
inputs=/home/my_home,/etc inputs=/home/user
#Output directory # Output directory. For remote backups, this is a path on the server ('~' and relative paths refer to the home directory on the server).
backup_dir=/media/Backup backup_dir=/media/Backup
#Exclude patterns. Use a comma to separate items # Files, directories and patterns to exclude from the backup. Multiple items can be separated using a comma.
exclude=.gvfs,.local/share/gvfs-metadata,.cache,.dbus,.Trash,.local/share/Trash,.macromedia,.adobe,.recently-used,.recently-used.xbel,.thumbnails exclude=*.bak
#Number of snapshots to keep (use -1 to keep all) # Number of old backups (i.e. excluding the one that's being created) to keep (use -1 to keep all)
keep=-1 keep=-1
# Uncomment the following section to enable backup to remote server through ssh
# [server]
# ssh_host=
# ssh_user=
# ssh_keyfile=
# remote_sudo=false
# numeric_ids=false
File diff suppressed because it is too large Load Diff