Compare commits

...

54 Commits

Author SHA1 Message Date
c715188973
Fix code with autopep8 2025-03-30 15:02:50 +02:00
57613649c2
Add missing type hints 2025-03-30 15:02:04 +02:00
67dbb49a67
Update PKGBUILD 2025-03-30 14:53:53 +02:00
e62a668f3e
Update metadata 2025-03-30 14:39:59 +02:00
bd8934d57f
Update version tag 2025-03-30 14:38:56 +02:00
96fe3c7813
Update man page 2025-03-30 14:38:29 +02:00
9fdb959540
Improve handling of user detection failure 2025-03-30 14:37:30 +02:00
eb889beee7
Add Python 3.13 to setup.cfg 2025-03-30 12:16:04 +02:00
2a37eb4172
Add PKGBUILD 2024-11-13 19:38:12 +01:00
45a07205a1
Add type hints plus minor code fixes 2024-09-28 09:47:33 +02:00
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
77661c0964
Handle getpass exception 2023-07-16 08:22:51 +02:00
e3a970217f
Improve logging 2023-06-25 11:49:02 +02:00
8968fcd1a8
Fix parsing option bug 2023-06-25 10:12:07 +02:00
35b87c859e
Add --user arg 2023-06-20 19:22:22 +02:00
f3d5ebd276
Merge branch 'development' 2023-06-20 17:36:40 +02:00
fb726a80ab
Fix bug
Remove forgotten test code -.-
2023-06-20 17:36:12 +02:00
4701ee0b05
Fix typo 2023-06-19 16:00:21 +02:00
dd779d242b
Fix crash when config file missing 2023-06-18 22:58:53 +02:00
22a3e8d60f
Make paramiko optional 2023-06-18 22:53:29 +02:00
a26182cedd
Update version number 2023-06-16 19:16:47 +02:00
5b3558c282
Merge branch 'development' 2023-06-16 19:15:44 +02:00
4e6adf3c56
Use dict for config options 2023-06-16 17:42:13 +02:00
ffed2dec90
Add numeric-ids option for rsync 2023-06-16 16:18:12 +02:00
169f824d83
Improve documentation 2023-06-15 23:15:00 +02:00
f77ff2d24f
Allow running remote rsync as sudo 2023-06-15 23:12:19 +02:00
ffe2b69c99
Fix error in man page 2023-06-15 22:12:38 +02:00
82b0ea88fa
Merge branch 'master' into development 2023-06-15 22:10:19 +02:00
970d3dde1e
Add manual selection of rsync options 2023-06-15 21:30:43 +02:00
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
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
f37cd89b4e
Fix parsing of old config file 2023-06-15 09:30:59 +02:00
d1b429d37a
Merge branch 'master' into development 2023-06-04 16:53:22 +02:00
cee4d13837
Fix bug
Fix crash when attempting to close a non-existent paramiko
SSH connection
2023-06-03 16:14:36 +02:00
252617e4f2
Fix old backups counting 2023-06-03 16:09:34 +02:00
809545b172
Explicitly close paramiko connection 2023-06-03 15:56:24 +02:00
b34627fe58
Improve readability 2023-06-03 15:44:31 +02:00
cd558e8608
Merge branch 'nolink' into development 2023-06-02 20:12:53 +02:00
78760bdda3
Merge branch 'master' into development 2023-06-02 18:38:54 +02:00
3d3fbbcbd9
Add password authentication for SSH 2023-06-02 00:09:14 +02:00
4f3d83f458
Update manpage 2023-06-01 22:18:32 +02:00
d48eaabbd3
Merge branch 'master' into development 2023-06-01 17:47:44 +02:00
7664fa1b33
Update README.md 2023-05-31 22:12:59 +02:00
98cb7f5822
Fix ssh authentication when running with sudo 2023-05-31 20:39:03 +02:00
b957200deb
Change missing hostkey policy 2023-05-31 19:30:31 +02:00
9e90d620e6
Merge branch 'master' into development 2023-05-31 19:21:11 +02:00
ba97b25e25
Add docstrings 2023-05-29 23:10:29 +02:00
335ad348e5
Update README.md 2023-05-29 21:56:58 +02:00
df18e383ed
Update dependencies 2023-05-29 19:02:05 +02:00
7eb71bc924
Add rsync compress option 2023-05-29 18:33:02 +02:00
c25ef52393
Implement remove old backups from server 2023-05-29 17:57:12 +02:00
24a59bde2d
Use ssh agent if available 2023-05-29 00:09:54 +02:00
88e6a9a141
Add incremental backups on server 2023-05-28 23:19:08 +02:00
38c090e257
Add basic remote backup functionality 2023-05-28 21:30:40 +02:00
7 changed files with 903 additions and 181 deletions

40
PKGBUILD Normal file
View File

@ -0,0 +1,40 @@
# PKGBUILD
# Maintainer: Daniele Fucini <dfucini [at] gmail [dot] com>
pkgname=simple_backup
pkgdesc='Simple backup script that uses rsync to copy files'
pkgver=4.1.6
pkgrel=1
url="https://git.shouldnt.work/fuxino/${pkgname}"
arch=('any')
license=('GPL-3.0-or-later')
makedepends=('git'
'python-setuptools'
'python-build'
'python-installer'
'python-wheel')
depends=('python>=3.10'
'rsync'
'python-dotenv')
optdepends=('python-systemd: use systemd log'
'python-dbus: for desktop notifications'
'python-paramiko: for remote backup through ssh')
conflicts=('simple_backup-git')
source=(git+${url}?signed#tag=${pkgver})
validpgpkeys=('7E12BC1FF3B6EDB2CD8053EB981A2B2A3BBF5514')
sha256sums=('b3b29d9e2e1b7b949e95674d9a401e8eeb0d5f898e8450473dce94f799ee9df3')
build()
{
cd ${srcdir}/${pkgname}
python -m build --wheel --no-isolation
}
package()
{
cd ${srcdir}/${pkgname}
python -m installer --destdir=${pkgdir} dist/*.whl
install -Dm644 ${pkgname}/${pkgname}.conf ${pkgdir}/usr/share/doc/${pkgname}/${pkgname}.conf
install -Dm644 man/${pkgname}.1 ${pkgdir}/usr/share/man/man1/${pkgname}.1
}

View File

@ -49,3 +49,23 @@ For Arch Linux and Arch-based distros, two packages are available in the AUR (au
- **simple_backup** for the release version
- **simple_backup-git** for the git version
## Remote backup
> **Warning**
> This feature is experimental
It's possible to use a remote server as destination for the backup. Just use the --username (or -u) and --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.

View File

@ -1,13 +1,13 @@
.TH SIMPLE_BACKUP 1 2023-06-01 SIMPLE_BACKUP 3.2.6
.TH SIMPLE_BACKUP 1 2025-03-30 SIMPLE_BACKUP 4.1.6
.SH NAME
simple_backup \- Backup files and folders using rsync
.SH SYNOPSIS
.BR simple_backup
.B simple_backup
\-h, \-\-help
.PD 0
.P
.PD
.BR simple_backup
.B simple_backup
[\-c, \-\-config FILE]
[\-i, \-\-input INPUT [INPUT...]]
[\-o, \-\-output DIR]
@ -16,71 +16,177 @@ simple_backup \- Backup files and folders using rsync
.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
.BR simple_backup
is a python script for performing backup of files and folders. 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.
.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
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.
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)
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).
.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
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)
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).
.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.
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.
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.
.TP
.B \-\-no\-syslog
Don't use systemd journal for logging
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 and \-v are used in any case. Not 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/etc/simple_backup/simple_backup.conf\(aq. Copy it to the default location
($HOME/.config/simple_backup) and edit it as needed.
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).
.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
The backup was completed without errors.
.TP
.B 1
No valid inputs selected for backup
No valid inputs selected for backup.
.TP
.B 2
Backup failed because output directory for storing the backup does not exist
Backup failed because output directory for storing the backup does not exist.
.TP
.B 3
Permission denied to access the output directory
Permission denied to access the output directory.
.TP
.B 4
rsync error (rsync returned a non-zero value)
rsync error (rsync returned a non-zero value).
.TP
.B 5
SSH connection failed.
.TP
.B 6
Bad configuration file.
.SH SEE ALSO
.BR rsync (1)
.SH AUTHORS
.MT https://github.com/Fuxino
.MT https://git.shouldnt.work/fuxino
Daniele Fucini
.ME

View File

@ -6,23 +6,22 @@ long_description = file: README.md
author = Daniele Fucini
author_email = dfucini@gmail.com
license = GPL3
url = https://github.com/Fuxino/simple_backup
url = https://git.shouldnt.work/fuxino
classifiers =
Development Status :: 5 - Production/Stable
Development Status :: 4 - Beta
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
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Topic :: System :: Archiving :: Backup
[options]
packages = simple_backup
python_requires = >=3.7
python_requires = >=3.10
install_requires =
python-dotenv
@ -31,6 +30,8 @@ JOURNAL =
systemd-python
NOTIFICATIONS =
dbus-python
REMOTE =
paramiko
[options.entry_points]
console_scripts =

View File

@ -1,3 +1,3 @@
"""Init."""
__version__ = '3.4.0'
__version__ = '4.1.6'

View File

@ -1,8 +1,8 @@
# Example config file for simple_backup
[default]
[backup]
# 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.
backup_dir=/media/Backup
@ -12,3 +12,11 @@ exclude=*.bak
# Number of old backups (i.e. excluding the one that's being created) to keep (use -1 to keep all)
keep=-1
# Uncomment the following section to enable backup to remote server through ssh
# [server]
# ssh_host=
# ssh_user=
# ssh_keyfile=
# remote_sudo=
# numeric_ids=

File diff suppressed because it is too large Load Diff