Closed ThomasWaldmann closed 2 months ago
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname="borgbackup", username="borg", port=22, allow_agent=True)
sftp = ssh.open_sftp()
path = "/srv/borg"
path = sftp._adjust_cwd(path)
t, msg = sftp._request(
paramiko.sftp.CMD_EXTENDED, "statvfs@openssh.com", path
)
if t != paramiko.sftp.CMD_EXTENDED_REPLY:
raise SFTPError("Expected extended reply response")
block_size = msg.get_int64()
fundamental_block_size = msg.get_int64()
blocks = msg.get_int64()
free_blocks = msg.get_int64()
available_blocks = msg.get_int64()
file_inodes = msg.get_int64()
free_file_inodes = msg.get_int64()
available_file_inodes = msg.get_int64()
sid = msg.get_int64()
flags = msg.get_int64()
name_max = msg.get_int64()
print(f"""
fbs {fundamental_block_size} B
bs {block_size} B
free {block_size * available_blocks / 2**20} MiB
""")
Does somebody know whether quotas are respected when reporting these values?
https://bugzilla.mindrot.org/show_bug.cgi?id=2992 being open seems to indicate that this is not the case, so statvfs results might be pointless when quotas are enabled.
Suggestion by amiconn via IRC: stat -f
Hmm, maybe it is easier to just sum up the stored object sizes.
Our .list
method reports name and size, so that can be solved as a cheap side effect whenever some operation needs to list all keys.
Some backends might be able to report a "free space" value:
df